flyx / NimYAML

YAML implementation for Nim
https://nimyaml.org
Other
189 stars 36 forks source link

Error in file serialization.nim at line 1377 #76

Closed illwieckz closed 4 years ago

illwieckz commented 4 years ago

Well, I don't know how to name this issue, I'm probably feeding bad code to nim, but instead of getting an error about what I wrote I got an unexpected exception in serialization.nim and I was asked to report this as a NimYAML bug.

This is my nim code in gm.nim file and I expect this file to have mistakes: this is the very first nim code I attempted to write after an hello world and I was expecting to experiment a bit by trial and error but unfortunately I did not got any review on my code but got review on NimYAML code instead.

import yaml/serialization, streams

var yamlPath: string = "file.yaml"

type
  Node = ref NodeObj
  NodeObj = object
    name: string
    left, right: Node

var package: Node

var stream = newFileStream(yamlPath)
load(stream, package)
stream.close()

This the YAML data in file.yaml (notice the list of list):

game:
  name: "Unvanquished"
  basename: "unvanquished"
content:
  - - baseurl: "https://raw.githubusercontent.com/Unvanquished/unvanquished-mapeditor-support/master/"
      filenames:
        - "LICENSE.md"
        - "README.md"
        - "games/unvanquished.game"
        - "unvanquished.game/default_build_menu.xml"
        - "unvanquished.game/pkg/entities.def"
        - "unvanquished.game/pkg/DEPS"
        - "unvanquished.game/game.xlink"

This is what I get when I run my code with this file:

$ nim c -r gm.nim 
Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: gm [Processing]
Hint: serialization [Processing]
Hint: tables [Processing]
Hint: hashes [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: bitops [Processing]
Hint: macros [Processing]
Hint: algorithm [Processing]
Hint: unicode [Processing]
Hint: typetraits [Processing]
Hint: streams [Processing]
Hint: times [Processing]
Hint: options [Processing]
Hint: posix [Processing]
Hint: parser [Processing]
Hint: taglib [Processing]
Hint: stream [Processing]
Hint: internal [Processing]
Hint: lex [Processing]
Hint: lexbase [Processing]
Hint: presenter [Processing]
Hint: deques [Processing]
Hint: hints [Processing]
Hint:  [Link]
Hint: operation successful (43786 lines compiled; 0.908 sec total; 89.523MiB peakmem; Debug Build) [SuccessX]
Hint: /home/illwieckz/dev/gamepack-manager/gm  [Exec]
[NimYAML] Error in file serialization.nim at line 1377:
Unexpected exception: YamlConstructionError
[NimYAML] Stacktrace:
Traceback (most recent call last)
/home/illwieckz/dev/gamepack-manager/gm.nim(14) gm
/home/illwieckz/.nimble/pkgs/yaml-0.12.0/yaml/private/internal.nim(17) load
Internal stacktrace:
/home/illwieckz/dev/gamepack-manager/gm.nim(14) gm
/home/illwieckz/.nimble/pkgs/yaml-0.12.0/yaml/serialization.nim(1372) load
/home/illwieckz/.nimble/pkgs/yaml-0.12.0/yaml/serialization.nim(1350) construct
/home/illwieckz/.nimble/pkgs/yaml-0.12.0/yaml/serialization.nim(1250) constructChild
/home/illwieckz/.nimble/pkgs/yaml-0.12.0/yaml/serialization.nim(1178) constructChild
/home/illwieckz/.nimble/pkgs/yaml-0.12.0/yaml/serialization.nim(949) constructObject
/home/illwieckz/.nimble/pkgs/yaml-0.12.0/yaml/serialization.nim(699) constructObjectDefault

[NimYAML] Please report this bug.
Error: execution of an external program failed: '/home/illwieckz/dev/gamepack-manager/gm '

The YAML code seems legit, PyYAML loads it properly:

In [1]: import yaml

In [2]: file=open("file.yaml", "r")

In [3]: yaml.load(file, Loader=yaml.CLoader)
Out[3]: 
{'game': {'name': 'Unvanquished', 'basename': 'unvanquished'},
 'content': [[{'baseurl': 'https://raw.githubusercontent.com/Unvanquished/unvanquished-mapeditor-support/master/',
    'filenames': ['LICENSE.md',
     'README.md',
     'games/unvanquished.game',
     'unvanquished.game/default_build_menu.xml',
     'unvanquished.game/pkg/entities.def',
     'unvanquished.game/pkg/DEPS',
     'unvanquished.game/game.xlink']}]]}

In [4]: file.close()
flyx commented 4 years ago

Sorry to keep you waiting. This was an error in exception propagation; code is fixed and yields the proper error description now:

Error: unhandled exception: While constructing NodeObj: Unknown field: "game" [YamlConstructionError]