pcottle/learnGitBranching · info · CommandResult
getHint()
Error message
getHint()
What it means
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.
Source
Thrown at src/js/level/index.js:624
}
getInstantCommands() {
var getHint = function() {
var hint = intl.getHint(this.level);
if (!hint || !hint.length) {
return intl.str('no-hint');
}
return hint;
}.bind(this);
return [
[/^help$|^\?$/, function() {
throw new Errors.CommandResult({
msg: intl.str('help-vague-level')
});
}],
[/^hint$/, function() {
throw new Errors.CommandResult({
msg: getHint()
});
}]
];
}
reset(command, deferred) {
this.gitCommandsIssued = [];
var commandStr = (command) ? command.get('rawStr') : '';
if (!this.testOptionOnString(commandStr, 'forSolution')) {
this.isShowingSolution = false;
}
if (this.solved) {
this.wasResetAfterSolved = true;
}
this.solved = false;
super.reset(command, deferred);View on GitHub (pinned to 5b09d0ff96)
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
Defensive patterns
Strategy: try-catch
Validate before calling
const level = levelStore.getCurrentLevel ? levelStore.getCurrentLevel() : null;
if (!level || !level.solution) { /* don't dispatch `hint` */ } Type guard
function hasHint(level) {
return !!(level && level.solution && level.solution.length);
} Try / catch
try {
dispatch('hint');
} catch (e) {
if (e instanceof Errors.CommandResult) { showMsg(e.msg); } else { throw e; }
} Prevention
- Only offer the hint UI when a level with a solution chain is active
- Always define solution arrays in custom level definitions
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- help-vague-level
- help-vague-builder
- <dynamic describe output: foundTag>
- <dynamic describe output: foundTag-N-g<id>>
- commit.getShowEntry()
AI-assisted analysis of pcottle/learnGitBranching@5b09d0ff96 (2026-08-27).
Data as JSON: /api/errors/48e91ab189dc6211.
Report an issue: GitHub.