MCPcopy Create free account
hub / github.com/GothenburgBitFactory/taskwarrior / assertValidJSON

Method assertValidJSON

src/Hooks.cpp:355–394  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

353
354////////////////////////////////////////////////////////////////////////////////
355void Hooks::assertValidJSON(const std::vector<std::string>& input,
356 const std::string& script) const {
357 for (auto& i : input) {
358 if (i.length() < 3 || i[0] != '{' || i[i.length() - 1] != '}') {
359 Context::getContext().error(format(STRING_HOOK_ERROR_OBJECT, Path(script).name()));
360 throw 0;
361 }
362
363 try {
364 json::value* root = json::parse(i);
365 if (root->type() != json::j_object) {
366 Context::getContext().error(format(STRING_HOOK_ERROR_OBJECT, Path(script).name()));
367 throw 0;
368 }
369
370 if (((json::object*)root)->_data.find("description") == ((json::object*)root)->_data.end()) {
371 Context::getContext().error(format(STRING_HOOK_ERROR_NODESC, Path(script).name()));
372 throw 0;
373 }
374
375 if (((json::object*)root)->_data.find("uuid") == ((json::object*)root)->_data.end()) {
376 Context::getContext().error(format(STRING_HOOK_ERROR_NOUUID, Path(script).name()));
377 throw 0;
378 }
379
380 delete root;
381 }
382
383 catch (const std::string& e) {
384 Context::getContext().error(format(STRING_HOOK_ERROR_SYNTAX, i));
385 if (_debug) Context::getContext().error(STRING_HOOK_ERROR_JSON + e);
386 throw 0;
387 }
388
389 catch (...) {
390 Context::getContext().error(STRING_HOOK_ERROR_NOPARSE + i);
391 throw 0;
392 }
393 }
394}
395
396////////////////////////////////////////////////////////////////////////////////
397void Hooks::assertNTasks(const std::vector<std::string>& input, unsigned int n,

Callers

nothing calls this directly

Calls 3

errorMethod · 0.80
typeMethod · 0.80
findMethod · 0.80

Tested by

no test coverage detected