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

Report_error in decode should throw an exception. #257

Closed
timschneider opened this issue Nov 22, 2018 · 3 comments
Closed

Report_error in decode should throw an exception. #257

timschneider opened this issue Nov 22, 2018 · 3 comments
Assignees
Milestone

Comments

@timschneider
Copy link
Contributor

timschneider commented Nov 22, 2018

def decode(self, data):
"""Return OrderedDictionary with Signal Name: object decodedSignal (support for multiplexed frames)
decodes only signals matching to muxgroup
:param data: bytearray .
i.e. bytearray([0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8])
:return: OrderedDictionary
"""
decoded = self.unpack(data)
if self.is_complex_multiplexed:
# TODO
raise DecodingComplexMultiplexed
elif self.is_multiplexed:
returnDict = dict()
# find multiplexer and decode only its value:
for signal in self.signals:
if signal.is_multiplexer:
muxVal = decoded[signal.name].raw_value
# find all signals with the identified multiplexer-value
for signal in self.signals:
if signal.mux_val == muxVal or signal.mux_val is None:
returnDict[signal.name] = decoded[signal.name]
return returnDict
else:
return decoded

Without an additional parameter we should disable report_error by default in decoded = self.unpack(data, False)

print(
'Received message 0x{self.id:08X} with length {rx_length}, expected {self.size}'.format(**locals()))

Should throw an exception.

@timschneider timschneider changed the title Unable to disable report_error in decode. Report_error in decode should throw an exception. Nov 22, 2018
@ebroecker ebroecker self-assigned this Nov 22, 2018
@altendky
Copy link
Collaborator

I agree with an exception over a print, but why should errors pass silently by default?

@timschneider
Copy link
Contributor Author

timschneider commented Dec 3, 2018

no sorry, this was just an intuitive way of reporting this "situation" like, oh, wait, no I see an output on the screen, what the heck? oh, ok it’s a debug output, but wait, how can I handle it? ummm, no way, cause it's a print - ok then turn it off and check it upfront. I don’t want to pass it silently.

So I think an exception is the way we should go.

Because my DBC Files are full of invalid Message Length and still valid, so I see a lot of output on the screen :)

ebroecker added a commit that referenced this issue Feb 15, 2019
@ebroecker ebroecker added this to the 0.8 milestone Feb 16, 2019
ebroecker added a commit that referenced this issue Feb 20, 2019
* Exception for wrong frame length #257
* add tests
@ebroecker
Copy link
Owner

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants