litedb-org/LiteDB · error · Exception
Unknow token after command
Error message
Unknow token after command
What it means
Thrown by StringScanner.ThrowIfNotFinish after consuming trailing whitespace if the scanner has not reached the end of the source. It signals a syntax error: extra, unexpected tokens remain after what should have been a complete command or expression in the shell/SQL parser.
Source
Thrown at LiteDB.Shell/Utils/StringScanner.cs:126
}
/// <summary>
/// Match if pattern is true in current cursor position. Do not change cursor position
/// </summary>
public bool Match(Regex regex)
{
var match = regex.Match(this.Source, this.Index, this.Source.Length - this.Index);
return match.Success;
}
/// <summary>
/// Throw syntax exception if not terminate string
/// </summary>
public void ThrowIfNotFinish()
{
this.Scan(@"\s*");
if (!this.HasTerminated) throw new Exception("Unknow token after command");
}
}
}View on GitHub (pinned to f906a5f850)
Solutions
- Inspect the full input string for stray characters or a second statement concatenated after the first.
- Trim and split multi-statement input into individual commands before scanning.
- If writing a custom shell command, ensure your Scan/Match consumes all intended tokens so none remain.
Defensive patterns
Strategy: validation
Validate before calling
// Before calling ThrowIfNotFinish, peek for leftover non-whitespace
scanner.Scan(@"\s*");
if (!scanner.HasTerminated)
{
// report the remaining tokens for easier debugging
var rest = scanner.Source.Substring(scanner.Index);
throw new Exception($"Unknow token after command: '{rest}'");
} Prevention
- Trim and split multi-statement input into one command per scan.
- When writing shell commands, consume all expected tokens so none remain.
- Inspect input for stray characters pasted after a complete command.
When it happens
Trigger: Passing a command string with trailing garbage after a complete token sequence, e.g. a shell or SQL fragment that the grammar parsed fully but left extra characters; malformed input fed to StringScanner-based parsing where ThrowIfNotFinish enforces full consumption.
Common situations: Typos adding stray characters after a command; copy-paste of multi-statement text where only one statement was expected; a parser bug that stops early leaving unparsed suffix tokens.
Related errors
AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13).
Data as JSON: /api/errors/bd7662daf058534d.
Report an issue: GitHub.