Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-8127

Refactor error location strings to not use words for better I18n support

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: PUP 5.3.3
    • Fix Version/s: PUP 5.3.4, PUP 5.4.0
    • Component/s: None
    • Labels:
      None
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      Hide
      The reporting of the location that an error was detect from is being updated in Puppet to enable better translations. The location is being change from using "at ", "at line", and "at file" to a statement of location '(file: <file>, line: <line>, column: <column>)'

      For example:
      Error: Something went wrong (file: /path//foo.pp:, line: 1, column: 9)
      Error: Something went wrong (file: /path//foo.pp, line: 1)
      Error: Something went wrong (line: 1, column :9)
      Error: Something went wrong (line: 1)
      Show
      The reporting of the location that an error was detect from is being updated in Puppet to enable better translations. The location is being change from using "at ", "at line", and "at file" to a statement of location '(file: <file>, line: <line>, column: <column>)' For example: Error: Something went wrong (file: /path//foo.pp:, line: 1, column: 9) Error: Something went wrong (file: /path//foo.pp, line: 1) Error: Something went wrong (line: 1, column :9) Error: Something went wrong (line: 1)
    • QA Risk Assessment:
      No Action

      Description

      For better translations we should look at how we add the location information to an error in 'ExternalFileError'. Instead of using words like 'at', 'at line', and 'in' we should change to something like '(file:line:pos)'. Then we have no words to translate while still providing the location information.

      I think replacing the output with the below. Based on which variables are set the names on the left, would cause the output on the right:

      file line pos -> (file:line:pos)
      file line -> (file:line)
      line pos -> (line:pos)
      line -> (line)
      

      An example with all location information set

      Error: Something went wrong (/Users/eric.delaney/work/my_repos/puppet/foo.pp:1:9)
      Error: Something went wrong (/Users/eric.delaney/work/my_repos/puppet/foo.pp:1)
      Error: Something went wrong (1:9)
      Error: Something went wrong (1)
      

      Places that need to be updated:
      ./puppet/error.rb - ExternalFileError -> to_s
      ./puppet/parser/resource.rb - def merge(resource)
      ./puppet/pops/validation.rb - DiagnosticFormatterPuppetStyle
      ./puppet/util/errors.rb - Puppet::Util::Errors -> def error_context
      ./puppet/util/log.rb - Puppet::Util::Log -> to_s line 403

      Some of the code that needs to be updated:

        module ExternalFileError
          # This module implements logging with a filename and line number. Use this
          # for errors that need to report a location in a non-ruby file that we
          # parse.
          attr_accessor :line, :file, :pos
       
          # May be called with 3 arguments for message, file, line, and exception, or
          # 4 args including the position on the line.
          #
          def initialize(message, file=nil, line=nil, pos=nil, original=nil)
            if pos.kind_of? Exception
              original = pos
              pos = nil
            end
            super(message, original)
            @file = file unless (file.is_a?(String) && file.empty?)
            @line = line
            @pos = pos
          end
          def to_s
            msg = super
            @file = nil if (@file.is_a?(String) && @file.empty?)
            if @file and @line and @pos
              "#{msg} at #{@file}:#{@line}:#{@pos}"
            elsif @file and @line
              "#{msg} at #{@file}:#{@line}"
            elsif @line and @pos
                "#{msg} at line #{@line}:#{@pos}"
            elsif @line
              "#{msg} at line #{@line}"
            elsif @file
              "#{msg} in #{@file}"
            else
              msg
            end
          end
        end
      

        Attachments

          Issue Links

            Activity

              jsd-sla-details-panel

                People

                • Assignee:
                  eric.delaney Eric Delaney
                  Reporter:
                  eric.delaney Eric Delaney
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:

                    Zendesk Support