{"record":{"id":"48e91ab189dc6211","repo":"pcottle/learnGitBranching","slug":"gethint","errorCode":null,"errorMessage":"getHint()","messagePattern":"getHint\\(\\)","errorType":"exception","errorClass":"CommandResult","httpStatus":null,"severity":"info","filePath":"src/js/level/index.js","lineNumber":624,"sourceCode":"  }\n\n  getInstantCommands() {\n    var getHint = function() {\n      var hint = intl.getHint(this.level);\n      if (!hint || !hint.length) {\n        return intl.str('no-hint');\n      }\n      return hint;\n    }.bind(this);\n\n    return [\n      [/^help$|^\\?$/, function() {\n        throw new Errors.CommandResult({\n          msg: intl.str('help-vague-level')\n        });\n      }],\n      [/^hint$/, function() {\n        throw new Errors.CommandResult({\n          msg: getHint()\n        });\n      }]\n    ];\n  }\n\n  reset(command, deferred) {\n    this.gitCommandsIssued = [];\n\n    var commandStr = (command) ? command.get('rawStr') : '';\n    if (!this.testOptionOnString(commandStr, 'forSolution')) {\n      this.isShowingSolution = false;\n    }\n    if (this.solved) {\n      this.wasResetAfterSolved = true;\n    }\n    this.solved = false;\n    super.reset(command, deferred);","sourceCodeStart":606,"sourceCodeEnd":642,"githubUrl":"https://github.com/pcottle/learnGitBranching/blob/5b09d0ff9678cad164f5a7488a279a44f90d7256/src/js/level/index.js#L606-L642","documentation":"Thrown when a user types `hint` while a level is active. The `getHint()` helper in level/index.js raises a CommandResult error whose message is the current level's next solution step (from its solution chain). This is the app's interactive 'give me a hint' mechanism — the throw is how the command pipeline surfaces text to the UI, not a real failure.","triggerScenarios":"Typing `hint` (matched by /^hint$/) in the command line while a level is loaded and initParseWaterfall dispatches the instant command. If the level has no hint/solution defined, getHint() itself may fail or return empty.","commonSituations":"Custom levels authored without a `solution` or hint chain; calling `hint` in sandbox/free-play mode where no level (and hence no hint) exists; tests that dispatch instant commands without loading a level first.","solutions":["Ensure a level is actually loaded before dispatching `hint` (check the level store state)","When authoring custom levels, always define a solution array so the hint chain has steps to reveal","In tests, load or mock a level before exercising the hint instant command","In free-play mode, catch CommandResult and show a friendly 'no hints outside levels' message"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const level = levelStore.getCurrentLevel ? levelStore.getCurrentLevel() : null;\nif (!level || !level.solution) { /* don't dispatch `hint` */ }","typeGuard":"function hasHint(level) {\n  return !!(level && level.solution && level.solution.length);\n}","tryCatchPattern":"try {\n  dispatch('hint');\n} catch (e) {\n  if (e instanceof Errors.CommandResult) { showMsg(e.msg); } else { throw e; }\n}","preventionTips":["Only offer the hint UI when a level with a solution chain is active","Always define solution arrays in custom level definitions"],"tags":["hint","level","instant-command","command-result"],"backgroundTag":"command-hint-unavailable","analyzedSha":"5b09d0ff9678cad164f5a7488a279a44f90d7256","analyzedAt":"2026-08-27T13:53:49.057Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}