SketchAPI
SketchAPI copied to clipboard
JSON Parse error when accessing some global Settings
When trying to access some Sketch’s preferences using the Settings API, we get a JSON Parse error. Running this on the Run Script panel…
const sketch = require('sketch')
console.log(sketch.Settings.globalSettingForKey('colorForMeasurements'))
…gives us:
SyntaxError: JSON Parse error: Unrecognized token '<'
at parse[native code] (/)
at onRun (/Users/ale/Library/Application Support/com.bohemiancoding.sketch3/Plugins/Untitled.sketchplugin:3:48)
Script executed in 0.052706s
The Settings implementation assumes all settings can be parsed as JSON, and that's not the case for the ones we store as binary blobs using NSKeyedArchiver (MSColorForSnapsAndGuidesKey, MSColorForMeasurementsKey and MSFlowArrowDrawingColorKey, apparently)
Implementation at https://github.com/sketch-hq/SketchAPI/blob/develop/Source/settings/Settings.js#L21-L27
I have also come across with this issue, they do not handle SyntaxError error when calling JSON.parse(<smth>)