Giter Site home page Giter Site logo

Parse error about fkyaml HOT 6 CLOSED

adjbcbc avatar adjbcbc commented on July 28, 2024 1
Parse error

from fkyaml.

Comments (6)

adjbcbc avatar adjbcbc commented on July 28, 2024 1

i have confirmed that it works in my environment as well. thank you for the quick response. this is a good project!

from fkyaml.

fktn-k avatar fktn-k commented on July 28, 2024

@adjbcbc
Thanks for sharing the issue and sorry for your inconvenience.

First of all, the fkyaml::node::deserialize() function doesn't expect a file path as an input.
If you want to deserialize file contents, you must first open a file and pass the file handle, i.e., FILE* or any object which can be interpreted as std::istream, like the following:

#include <iostream>
#include <fstream> // ADDED
#include "fkYAML/node.hpp"
int main() {                                                       
    std::ifstream ifs("./yamltest");                    // ADDED
    fkyaml::node root = fkyaml::node::deserialize(ifs); // CHANGED

    for (const auto &ctx : root["contexts"]) {
        std::cout << ctx["context"]["cluster"].get_value<std::string>(); // error
        std::cout << ctx["context"]["bug"].get_value<std::string>();      // error
    }
}

If a file path is given, fkYAML tries to parse the string ./yamltest itself, which is why you encountered the reported error.

So, I tried the input with the above code and found a bug thanks to your report.
There seems to be a bug in handling indentation after a block sequence with the same indentation as its key node (line 9 in the YAML file).
Due to the bug, the node associated with the bug key was mistakenly parsed as a child of the sequence node with extension key.

Although I'm going to fix the bug hopefully this weekend, a quick workaround is to use the slightly modified version which works fine in my environment:

contexts:                                                                    
- context:                                                                   
    cluster: abcdef                                                          
    extension:                                                               
      - extension:                                                             
          last-update: blah                                                    
          version: 0.1.0                                                       
        name: blah                                                             
    bug: default                                                             
  ctx: ctx    

from fkyaml.

fktn-k avatar fktn-k commented on July 28, 2024

@adjbcbc
The PR #348 has fixed the bug in parsing the YAML snippet you shared above.
Could you confirm if you can now get the correct parse result on the latest develop branch?

from fkyaml.

adjbcbc avatar adjbcbc commented on July 28, 2024

thinks for quick fix
i have confirmed that above example has been corrected properly.
but, i originally intended to try following file, but now encounted the following error.

terminate called after throwing an instance of 'fkyaml::v0_3_7::parse_error'
  what():  parse_error: invalid flow mapping ending is found. (at line 26, column 14)
Aborted (core dumped)
apiVersion: v1
clusters:
- cluster:
    certificate-authority: /home/x/.minikube/ca.crt
    extensions:
    - extension:
        last-update: Mon, 27 May 2024 06:05:41 UTC
        provider: minikube.sigs.k8s.io
        version: v1.32.0
      name: cluster_info
    server: https://192.168.30.12:8441
  name: minikube
contexts:
- context:
    cluster: minikube
    extensions:
    - extension:
        last-update: Mon, 27 May 2024 06:05:41 UTC
        provider: minikube.sigs.k8s.io
        version: v1.32.0
      name: context_info
    namespace: default
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /home/x/.minikube/profiles/minikube/client.crt
    client-key: /home/x/.minikube/profiles/minikube/client.key

how can i solve the above issue?
tools like kubectl had no problems reading that file

from fkyaml.

fktn-k avatar fktn-k commented on July 28, 2024

@adjbcbc
Thanks for confirming the fix and reporting the new issue.

The above error was caused because I forgot to implement for empty flow containers in the PR #350.
I can't think of a workaround for this issue, but it shouldn't require any major changes and will be fixed soon.

from fkyaml.

fktn-k avatar fktn-k commented on July 28, 2024

The error on empty flow containers has been fixed in the PR #351.
And I've checked that the parsing of the YAML file shared here succeeds with the modified parser, just locally though.
Can you please check if it can now be parsed with no issue in your environment too?

from fkyaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.