Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: invalid option '%-100' to 'format' #415

Closed
wincent opened this issue Dec 13, 2022 · 2 comments
Closed

bug: invalid option '%-100' to 'format' #415

wincent opened this issue Dec 13, 2022 · 2 comments

Comments

@wincent
Copy link
Owner

wincent commented Dec 13, 2022

I don't have a reliable repro for this yet, but this code1:

│ -- Right pad so that selection highlighting is shown across full width.
│ if width < 104 then
│ │ if #line > 99 then
│ │ │ -- No padding needed.
│ │ │ line = prefix .. line
│ │ else
│ │ │ line = prefix .. string.format('%-' .. (width - #prefix) .. 's', line)
│ │ end
│ else
│ │ -- Avoid: "invalid option" caused by format argument > 99.
│ │ line = prefix .. string.format('%-99s', line)
│ │ local diff = width - line:len()
│ │ if diff > 0 then
│ │ │ line = line .. string.rep(' ', diff)
│ │ end
│ end

can blow up with:

Error executing lua callback: ...command-t/lua/wincent/commandt/private/match_listing.lua:65: invalid option '%-100' to 'format'

if width is, say, 103, and #line is less 99 or less.

Very likely cause is this line:

local width = self._window:width() or vim.o.columns -- BUG: width may be cached/stale

Footnotes

  1. Sorry about the formatting; my copy-paste brought in indent markers from Vim.

@wincent wincent changed the title bug: `invalid option '%-100' to 'format' bug: invalid option '%-100' to 'format' Dec 13, 2022
@Rijalamagaha

This comment was marked as spam.

@trotzig
Copy link
Contributor

trotzig commented Jan 6, 2023

I can confirm the fix in 0f22018 resolves the issue in one of my repos. 🎄🎉

Padmamanickam added a commit to Padmamanickam/command-t that referenced this issue Feb 6, 2023
As described in the related issue, I didn't have a reliable repro, but I
have seen this error message on occasion:

> Error executing lua callback:
> ...command-t/lua/wincent/commandt/private/match_listing.lua:65:
> invalid option '%-100' to 'format'

I first suspected a bad cached value, and that may be the case, but
either way, the arithmetic here seems off, as it will allow a bad format
to occur whenever `width` is, say, 103 (`width` usually comes from
a `Window` instance, with `vim.o.columns` used as a fallback).

I was finally able to repro by setting `margin` to `1` and then
adjusting my window size until `'columns'` was (I think) 107.

Closes: wincent/command-t#415
ColonQExclamationMark pushed a commit to ColonQExclamationMark/qfview.nvim that referenced this issue Aug 7, 2023
ColonQExclamationMark pushed a commit to ColonQExclamationMark/qfview.nvim that referenced this issue Aug 7, 2023
ColonQExclamationMark added a commit to ColonQExclamationMark/qfview.nvim that referenced this issue Aug 7, 2023
When the value for string.format gets above 99, then you get an error message saying "invalid option %-XXX for format". see e.g wincent/command-t#415
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants