canonical / pebble

Take control of your internal daemons!
https://canonical-pebble.readthedocs-hosted.com/
GNU General Public License v3.0
143 stars 54 forks source link

fix(daemon): add-notice API shouldn't error if no data is provided #321

Closed benhoyt closed 10 months ago

benhoyt commented 10 months ago

During code review of #296, when I'd switched the add-notice API endpoint to use json.RawMessage for the data field, it no longer handled the case where the data field wasn't present (which is perfectly valid if you don't have data to attach). This made pebble notify fail like so:

$ pebble notify example.com/fizzbuzz
error: cannot decode notice data: unexpected end of JSON input

However, it does this work if you provide one or more data keys/values:

$ pebble notify example.com/fizzbuzz kee=valyou
Recorded notice 1

This PR is a trivial fix for the (first) no-data case, and also adds a test case for the no-data case.

benhoyt commented 10 months ago

Trivial bug fix, merged without further review.