pcottle/learnGitBranching · error · GitError

git-error-options

Error message

git-error-options

What it means

This hg command shim accepts several option flags (-d, -s, -b, ...) and defines throwE(), which raises GitError('git-error-options') whenever the option combination is invalid — specifically when both or neither of the mutually required options are present ('if we have both OR if we have neither').

Source

Thrown at src/js/mercurial/commands.js:165

        } else {
          delegate.name = 'branch';
        }
      }

      return delegate;
    }
  },

  rebase: {
    regex: /^hg +rebase($|\s+)/,
    options: [
      '-d',
      '-s',
      '-b'
    ],
    execute: function(engine, command) {
      var throwE = function() {
        throw new GitError({
          msg: intl.str('git-error-options')
        });
      };

      var options = command.getOptionsMap();
      // if we have both OR if we have neither
      if ((options['-d'] && options['-s']) ||
          (!options['-d'] && !options['-s'])) {
      }

      if (!options['-b']) {
        options['-b'] = ['.'];
      }

      command.setOptionsMap(options);
      command.mapDotToHead();
      options = command.getOptionsMap();

View on GitHub (pinned to 5b09d0ff96)

Solutions

  1. Supply exactly one of the relevant option flags (-d, -s, or -b) as documented for this hg command
  2. Check `command.getOptionsMap()` contents before executing when commands are built dynamically

Example fix

// before
hg bookmark
// after
hg bookmark -d name
Defensive patterns

Strategy: validation

Validate before calling

const opts = command.getOptionsMap();
const count = ['-d','-s','-b'].filter(k => opts[k]).length;
if (count !== 1) { reject('provide exactly one of -d/-s/-b'); }

Type guard

function exactlyOne(map, keys) {
  return keys.filter(k => Boolean(map[k])).length === 1;
}

Try / catch

try { cmd.execute(engine, command); } catch (e) { if (e instanceof GitError && /options/.test(e.msg)) { showUsage(); } else throw e; }

Prevention

When it happens

Trigger: Calling the command with an options map where the required pair of options are both set, or both absent — throwE() is invoked from the execute path (referenced by dest and commandConfig) whenever the validated combination fails.

Common situations: Running the hg bookmark/branch-like command with no options at all, or with the full set of options simultaneously; passing empty options from a scripted harness.

Related errors


AI-assisted analysis of pcottle/learnGitBranching@5b09d0ff96 (2026-08-27). Data as JSON: /api/errors/34f441ac64670861. Report an issue: GitHub.