Skip to content

Emoji in command output seems to break #781

Closed

Description

@clemens

The latest release seems to have an issue when emojis (or more general: UTF-8 characters) are used in a command's output.

Here's the error i'm getting:

Checks for vulnerable versions of 3rd party packages.......[NpmAudit] FAILED
Hook raised unexpected error
"\xF0" on US-ASCII
/var/lib/gems/2.5.0/gems/overcommit-0.59.0/lib/overcommit/subprocess.rb:105:in `convert'
/var/lib/gems/2.5.0/gems/overcommit-0.59.0/lib/overcommit/subprocess.rb:105:in `to_utf8'
/var/lib/gems/2.5.0/gems/overcommit-0.59.0/lib/overcommit/subprocess.rb:55:in `spawn'
/var/lib/gems/2.5.0/gems/overcommit-0.59.0/lib/overcommit/utils.rb:187:in `execute'
/var/lib/gems/2.5.0/gems/overcommit-0.59.0/lib/overcommit/hook_context/base.rb:33:in `execute_hook'
/var/lib/gems/2.5.0/gems/overcommit-0.59.0/lib/overcommit/hook_loader/plugin_hook_loader.rb:85:in `run'
/var/lib/gems/2.5.0/gems/overcommit-0.59.0/lib/overcommit/hook/base.rb:47:in `block in run_and_transform'
/var/lib/gems/2.5.0/gems/overcommit-0.59.0/lib/overcommit/utils.rb:260:in `with_environment'
/var/lib/gems/2.5.0/gems/overcommit-0.59.0/lib/overcommit/hook/base.rb:47:in `run_and_transform'
/var/lib/gems/2.5.0/gems/overcommit-0.59.0/lib/overcommit/hook_runner.rb:162:in `run_hook'
/var/lib/gems/2.5.0/gems/overcommit-0.59.0/lib/overcommit/hook_runner.rb:98:in `block in consume'
/var/lib/gems/2.5.0/gems/overcommit-0.59.0/lib/overcommit/hook_runner.rb:94:in `loop'
/var/lib/gems/2.5.0/gems/overcommit-0.59.0/lib/overcommit/hook_runner.rb:94:in `consume'

The command looks like this:

NpmAudit:
  description: 'Checks for vulnerable versions of 3rd party packages'
  enabled: true
  command: ['bin/npm-audit']

The binary looks like this:

#!/bin/bash

$(npm bin)/better-npm-audit audit

The output from the command is this:

Screenshot 2022-04-29 at 11 52 56


I'm assuming this is related to #766.

OS: Debian 10 in Docker container
overcommit version: 0.59.0 (it works fine in 0.58.0)

Activity

  1. clemens commented on Apr 29, 2022

    @clemens
    Author

    Here's how I've worked around it for now:

    #!/bin/bash
    
    $(npm bin)/better-npm-audit audit > /dev/null && echo "All good!"
  2. Drowze commented on May 1, 2022

    @Drowze
    Contributor

    I debugged this a bit but I'm still not sure about the proper fix... It also doesn't help that #766 didn't add a test documenting the intended behaviour of to_utf8 method 🤔

    Here's a minimal Dockerfile to reproduce the bug:
    (note: the debian image on this Dockerfile does not define any locale; Encoding.locale_charmap returns ANSI_X3.4-1968 and the code breaks on gems/overcommit-0.59.0/lib/overcommit/subprocess.rb:105:in 'convert')

    FROM debian
    
    RUN apt update -y && apt install -y ruby git && gem install bundler overcommit
    WORKDIR some-dir
    
    # setup a git repo with a utf-8 commit message
    RUN git init && \
      git config --local user.name "Overcommit Tester" && \
      git config --local user.email "[email protected]" && \
      git commit --allow-empty -m "🤝 UTF-8 text"
    
    # add and install a pre-commit hook that checks a commit message
    RUN echo "PreCommit:\n  CapitalizedSubject:\n    enabled: true" > .overcommit.yml && overcommit --install
    
    # amend the commit to trigger the pre-commit hook; this raises an error
    RUN git commit --amend --no-edit

    If I understood it correctly, v0.59 breaks on utf8 strings for any unix system that does not define an utf8 locale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions