Numerical value for 'source-tag' key causes confusing error

Bug #1612373 reported by Wesley Wiedenmeier
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snapcraft
Confirmed
Undecided
Unassigned

Bug Description

Many projects on github have numerical tags that represent a release version.
The most obvious way to pull a specific revision of something is to use something like 'source-tag: 2.14'.

However, this fails with the message:
'Can't convert 'float' object to str implicitly'

The same snapcraft configuration file works as expected if the tag is enclosed in quotes, but it would be nice to not require the user to put quotes around the tag. It should work perfectly fine to add a call to str() in snapcraft.internal.sources.Base.__init__

Also, if this is something that won't be fixed, then either the error should be caught and a more helpful error message should be displayed, or a stacktrace should be displayed to make it easier to track the issue down.

There is an example snapcraft configuration file attached that demonstrates the bug.

Tags: yaml
Revision history for this message
Wesley Wiedenmeier (wesley-wiedenmeier) wrote :
Revision history for this message
Kyle Fazzari (kyrofa) wrote :

Note that `source-tag: 2.14` is implicitly a float in the YAML spec. Even if we converted it to a string after parsing, it would parse `2.10` as `2.1` and so on. You need to tell YAML that it's explicitly a string if you intend for it to be so (by either using quotes as you mentioned or tagging the scalar with !!str).

Snapcraft can implement a custom parser to make this a bit nicer, but I'm a little uncomfortable treating YAML in a non-standard way.

Revision history for this message
Wesley Wiedenmeier (wesley-wiedenmeier) wrote :
Revision history for this message
Kyle Fazzari (kyrofa) wrote :

> See https://github.com/Magical-Chicken/snapcraft for a simple fix

And does that work for `source-tag: 2.10`?

Revision history for this message
Wesley Wiedenmeier (wesley-wiedenmeier) wrote :

No, you're right it wouldn't work for 2.10 or anything like that, thanks for pointing that out. Yeah, it does seem risky to try to parse yaml in a non standard way, so I guess that this probably shouldn't be changed.

Still though, it would be good to catch the error when formatting the command and display a message telling the user that they need quotes

Revision history for this message
Kyle Fazzari (kyrofa) wrote :

> Still though, it would be good to catch the error when formatting the command and display a message telling the user that they need quotes.

I agree that this failure is terrible. Perhaps this is something that should be enforced at the schema level. We'll investigate, thank you!

Changed in snapcraft:
status: New → Confirmed
summary: - snapcraft should support numerical values for 'source-tag' key
+ Numerical values for 'source-tag' key throws exceptions
summary: - Numerical values for 'source-tag' key throws exceptions
+ Numerical value for 'source-tag' key causes confusing error
Leo Arias (elopio)
tags: added: yaml
Revision history for this message
林博仁(Buo-ren, Lin) (buo-ren-lin) wrote :

Maybe catch this exception in particular and print a customized message for it?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.