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

Code generation fails with unhelpful error message #431

Open
maxd-nordic opened this issue May 14, 2024 · 1 comment
Open

Code generation fails with unhelpful error message #431

maxd-nordic opened this issue May 14, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@maxd-nordic
Copy link

I get this error:

assert (''.join(type_names[type_name]) == ''.join(type_def[0])), f"""

When generating an encoder for the env-object from the following CDDL:

lwm2m_senml = [1* record]

record = {
	? bn => tstr,            ; Base Name
	? bt => int .size 8,     ; Base Time
	? n => tstr,             ; Name
	? t => int .size 8,      ; Time
	? ( vi => int .size 8 // ; Integer Value
	    vf => float       // ; Float Value
	    vs => tstr        // ; String Value
	    vb => bool        // ; Boolean Value
	    vd => bstr        // ; Data Value
	    vlo => tstr ),       ; Object Link Value
	0*5 key-value-pair       ; To handle unordered maps; length-first ordered map keys
}

; now define the generic versions
key-value-pair = ( int => value )

value = tstr / bstr / int .size 8 / float / bool

n  = 0
t = 6
bn = -2
bt = -3
vi = 2
vf = 2
vs = 3
vd = 8
vb = 4
vlo = "vlo"

degrees = vf
percent = vf
pascals = vf
aqi = vi
timestamp = vi
temperature_rid = n
humidity_rid = n
pressure_rid = n
timestamp_rid = n
iaq_rid = n
env-object = [
	{
		bn => "14205/0/",  ; Custom Environment information object
		temperature_rid => "0",          ; Temperature Resource ID
		degrees => float,       ; temperature in degrees Celsius
	},
	{
		humidity_rid => "1",          ; Humidity Resource ID
		percent => float,       ; Relative humidity in percent
	},
	{
		pressure_rid => "2",          ; Atmospheric pressure Resource ID
		pascals => float,       ; Atmospheric pressure in pascals
	},
	{
		iaq_rid => "10",          ; Air Quality Index Resource ID
		aqi => int .size 4  ; AQI value
	},
	{
		timestamp_rid => "99",          ; Timestamp Resource ID
		timestamp => int .size 8   ; UNIX timestamp in milliseconds
	},
]

I'm using the latest pip release 0.8.1.

Could we at least get a useful error message here?

@maxd-nordic
Copy link
Author

An extra indirection makes the code generation succeed:

temperature = {
	n => "0",          ; Temperature Resource ID
	vf => float,       ; temperature in degrees Celsius
}
humidity = {
	n => "1",          ; Humidity Resource ID
	vf => float,       ; Relative humidity in percent
}
pressure = {
	n => "2",          ; Atmospheric pressure Resource ID
 	vf => float,       ; Atmospheric pressure in pascals
}
iaq = {
	n => "10",          ; Air Quality Index Resource ID
	vi => int .size 4  ; AQI value
}
timestamp = {
	n => "99",          ; Timestamp Resource ID
	vi => int .size 8   ; UNIX timestamp in milliseconds
}


env-object = [
	temperature,
	humidity,
	pressure,
	iaq,
	timestamp
]

@oyvindronningstad oyvindronningstad added the enhancement New feature or request label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants