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

🐛 Panic/crash when diffing Vue files with pug syntax in the template #634

Closed
CodeGradox opened this issue Jun 19, 2021 · 8 comments
Closed

Comments

@CodeGradox
Copy link

Delta crashes when diffing a Vue file with uses the pug template engine.

[~/projects/delta-vue-bug] > (master) RUST_BACKTRACE=full git diff
thread 'main' panicked at 'Can only call resolve on linked references: ByScope { scope: <text.pug>, sub_context: None }', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/syntect-4.5.0/src/parsing/syntax_definition.rs:191:18
stack backtrace:

App.vue

───┐
1: │
───┘
0:     0x559b27eff4e0 - <unknown>
   1:     0x559b27f204ef - <unknown>
   2:     0x559b27efbff2 - <unknown>
   3:     0x559b27f01645 - <unknown>
   4:     0x559b27f010f3 - <unknown>
   5:     0x559b27f01c4d - <unknown>
   6:     0x559b27f017e7 - <unknown>
   7:     0x559b27eff99c - <unknown>
   8:     0x559b27f01749 - <unknown>
   9:     0x559b27ce188b - <unknown>
  10:     0x559b27e7c0c2 - <unknown>
  11:     0x559b27e7a8f8 - <unknown>
  12:     0x559b27e71888 - <unknown>
  13:     0x559b27d010c1 - <unknown>
  14:     0x559b27cfed54 - <unknown>
  15:     0x559b27d53d09 - <unknown>
  16:     0x559b27d514d2 - <unknown>
  17:     0x559b27d6fbee - <unknown>
  18:     0x559b27d7220c - <unknown>
  19:     0x559b27d22c53 - <unknown>
  20:     0x559b27d233b9 - <unknown>
  21:     0x559b27f0214a - <unknown>
  22:     0x559b27d768e2 - <unknown>
  23:     0x7f4ab34ccb25 - __libc_start_main
  24:     0x559b27ce293e - <unknown>
  25:                0x0 - <unknown>

Delta is setup like this in ~/.gitconfig

[core]
  pager = delta --light

To reproduce simply create a new folder and init git. Then add the following Vue file and commit it. Finally, you add a change to code inside the <template> tag and run git diff.

<template lang="pug">
p
  | Hello world
</template>

<script>
export default {}
</script>

Changing anything inside the <script> tag does not cause a panic. Delta does not panic if I remove the lang="pug" from the <template> tag.

@dandavison
Copy link
Owner

@sharkdp would you mind suggesting next steps here? (I know you have experience with several similar issues). The example code fragment below, when named with a .vue suffix, crashes bat, and delta, and syncat. I'm not quite sure whose the bug is -- is it in the syntax definition repo?


@CodeGradox -- thanks. I believe this is a bug in an upstream library, but I am not sure whether it is in https://github.com/vuejs/vue-syntax-highlight or https://github.com/trishume/syntect, or both. Your example file also crashes bat which, like delta, uses syntect for syntax highlighting. The bug can be reproduced in the syntect repo, using the syntax definition file from bat, with a line like this:

$ cargo run --example syncat -- --extra-syntaxes $BAT_REPO/assets/syntaxes/02_Extra/Vue delta-634-crash.vue
thread 'main' panicked at 'Can only call resolve on linked references: ByScope { scope: <text.pug>, sub_context: None }', src/parsing/syntax_definition.rs:191:18

where delta-634-crash.vue contains

<template lang="pug">
hello
</template>

I think that syntect does not promise never to panic with any user syntax definition, therefore this is not necessarily a bug in syntect. bat looks to be running the current HEAD of the newsyntax-3.3.6 branch, so unfortunately it may not be as simple as just updating the Vue syntax definitions in the bat repo: https://github.com/sharkdp/bat (delta copies the syntax files from bat).

   0: rust_begin_unwind
             at /rustc/88f19c6dab716c6281af7602e30f413e809c5974/library/std/src/panicking.rs:493:5
   1: std::panicking::begin_panic_fmt
             at /rustc/88f19c6dab716c6281af7602e30f413e809c5974/library/std/src/panicking.rs:435:5
   2: syntect::parsing::parser::ParseState::push_meta_ops
   3: syntect::parsing::parser::ParseState::parse_line
   4: syntect::easy::HighlightLines::highlight
   5: delta::paint::Painter::get_syntax_style_sections_for_lines
   6: delta::paint::Painter::paint_buffered_minus_and_plus_lines
   7: delta::delta::delta
   8: delta::run_app
   9: delta::main

@dandavison
Copy link
Owner

I see that something like this is fine (e.g. does not crash bat)

<template lang="pugxxx">
hello
</template>

but valid references such as lang="pug" and lang="jade" both do cause the crash.

@sharkdp
Copy link

sharkdp commented Jun 29, 2021

@dandavison Thank you for the mention. Some possible next steps are discussed in this ticket: sharkdp/bat#915.

In particular, see this comment by @keith-hall. The tracking issue to fix this in bat is here: sharkdp/bat#1616

@dandavison
Copy link
Owner

Oh, thank you @sharkdp -- I somehow missed that issue.

@sharkdp
Copy link

sharkdp commented Aug 2, 2021

@dandavison FYI: sharkdp/bat#1771

@hedefalk
Copy link

+1 on this.

@dandavison
Copy link
Owner

@hedefalk bat and syntect contributors are working on this, see sharkdp/bat#915. Currently the demo Vue file still crashes bat, so I think we should follow / help with their work, and then adopt their solution.

@CodeGradox
Copy link
Author

Long time no see.

It looks like sharkdp/bat#915 has been resolved.
I tested with delta version 0.13.0 and it does not crash on Vue files.

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

4 participants