MartinKoch123 / yaml

MATLAB YAML parser and emitter based on SnakeYAML
MIT License
22 stars 7 forks source link

Problem with 'dumpFile' #5

Closed SDADEEC closed 2 years ago

SDADEEC commented 2 years ago

Hi, Thank you for designing this tool.

I'm trying to write a simple struct to a yaml file using 'dumpFile' function. Here is what I write

data_towrite = strcut('int_data', int32(1), 'str_data', 'str');
yaml.dumpFile("my.yaml",data_towrite);

But I get the error messages for yaml.dumpFile("my.yaml",data_towrite);:

Check for incorrect argument data type or missing argument in call to function 'setDefaultFlowStyle'.

Error in yaml.dump/getDumperOptions (line 145)
        opts.setDefaultFlowStyle(styleFields(styleIndex).get([])); %

Error in yaml.dump (line 56)
dumperOptions = getDumperOptions(style);

Error in yaml.dumpFile (line 42)
yamlString = yaml.dump(data, style);

Could you please help me with that?

MartinKoch123 commented 2 years ago

Hello Jianeng,

I can't reproduce your issue, unfortunatly. Are you using the newest release, 1.5.1? What Matlab version and what operating system are you using?

SDADEEC commented 2 years ago

Hi Martin,

Thanks for replying.

I'm using the newest release (1.5.1). Matlab version is R2021a (9.10.0.1602886) and OS is Ubuntu 20.04

MartinKoch123 commented 2 years ago

I have an idea what the problem might be, but it will take me some time to fix it.

As a workaround, you could remove line 145 opts.setDefaultFlowStyle(styleFields(styleIndex).get([])); of dump.m. which will remove the error but also disable the flow style feature.

SDADEEC commented 2 years ago

Hi Martin,

Thank you very much. After removing that line, the error is solved.

MartinKoch123 commented 2 years ago

@SDADEEC Since I cant reproduce the bug on my machine, could you please quickly try out the new version v1.5.2 and see if yaml.dump([1, 2, 3], "block") executes without problem?

SDADEEC commented 2 years ago

Hi Martin,

Sure, I followed your recent commit to modify the code (seems v1.5.2 is not available in the Matlab Add-on) and the result after executing your provided code is:

>> yaml.dump([1, 2, 3], "block")

ans = 

    "- 1.0
     - 2.0
     - 3.0
     "

where 'ans' is 1*1 string

For v1.5.1, after removing opts.setDefaultFlowStyle(styleFields(styleIndex).get([]));, the result I get is:

>> yaml.dump([1, 2, 3], "block")

ans = 

    "[1.0, 2.0, 3.0]
     "
MartinKoch123 commented 2 years ago

Hi Jianeng,

I forgot that it takes an hour or so until the release is available in Matlab file exchange. But from your feedback it seems like everything is working correctly now. Thanks for reporting the bug and have a nice day.