Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic usage of parsing string fails with isNil is a user defined error #23

Closed
xmonader opened this issue Sep 19, 2018 · 8 comments
Closed

Comments

@xmonader
Copy link

xmonader commented Sep 19, 2018

import parsetoml


let table1 = parsetoml.parseString(""""
[input]
file_name = "test.txt"

[output]
verbose = true
""")

error:

.nimble/pkgs/parsetoml-0.3.2/parsetoml.nim(1284, 8) Error: usage of 'isNil' is a user-defined error

I'm using nim head

@xmonader
Copy link
Author

xmonader commented Sep 19, 2018

also when compiling with --nilseqs:on

import parsetoml


let table1 = parsetoml.parseString(""""
[input]
file_name = "test.txt"

[output]
verbose = true
""")

gives

testtoml.nim(4)          testtoml
parsetoml.nim(991)       parseString
parsetoml.nim(985)       parseStream
parsetoml.nim(763)       parseKeyValuePair
Error: unhandled exception: (3:12) key names cannot contain spaces [TomlError]
Error: execution of an external program failed: '/home/ahmed/testtoml '

@kaushalmodi
Copy link
Member

I think that error is because of using 4 instead of 3 quotes on line 3:

let table1 = parsetoml.parseString(""""

@xmonader
Copy link
Author

@kaushalmodi you're correct my bad thanks

@kaushalmodi
Copy link
Member

The issue is still not technically closed, right? It would still fail on devel when not using that switch, right?

@PMunch
Copy link
Member

PMunch commented Sep 19, 2018

Yeah, the error message is strange but it's cause by the four " characters. Should probably be a better error message. And we should update this to work with the new nil behaviour so I'm keeping this open for now.

@PMunch PMunch reopened this Sep 19, 2018
@iffy
Copy link
Contributor

iffy commented Sep 20, 2018

I'm getting the same error message for this code:

import strutils
import strformat
import parseopt

var
    filename: string
var p = initOptParser()
for kind, key, val in p.getopt():
    case kind
    of cmdArgument:
        filename = key
    of cmdLongOption:
        discard
    of cmdShortOption:
        discard
    of cmdEnd:
        discard
if filename.isNil():
    echo "Error: provide a filename"
    quit(1)

echo "Success"

How should I check if a string is nil?

@PMunch
Copy link
Member

PMunch commented Sep 20, 2018

You can't any longer, you just check if it is equal to "". Libraries that used nil checking should switch over to using options

EDIT: Of course in that case you should simply check if filename exists on the filesystem.

@PMunch
Copy link
Member

PMunch commented Sep 20, 2018

This should be fixed in 6ed000e

@PMunch PMunch closed this as completed Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants