Exception: Bundler::Dsl::DSLError

Inherits:
GemfileError show all
Defined in:
lib/bundler/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BundlerError

status_code

Constructor Details

#initialize(description, dsl_path, backtrace, contents = nil) ⇒ DSLError

Returns a new instance of DSLError.

Parameters:

  • backtrace (Exception)

    @see backtrace

  • dsl_path (String)

    @see dsl_path



385
386
387
388
389
390
391
392
# File 'lib/bundler/dsl.rb', line 385

def initialize(description, dsl_path, backtrace, contents = nil)
  @status_code = $!.respond_to?(:status_code) && $!.status_code

  @description = description
  @dsl_path    = dsl_path
  @backtrace   = backtrace
  @contents    = contents
end

Instance Attribute Details

#backtraceException (readonly)

Returns the backtrace of the exception raised by the evaluation of the dsl file.

Returns:

  • (Exception)

    the backtrace of the exception raised by the evaluation of the dsl file.



380
381
382
# File 'lib/bundler/dsl.rb', line 380

def backtrace
  @backtrace
end

#descriptionString (readonly)

Returns the description that should be presented to the user.

Returns:

  • (String)

    the description that should be presented to the user.



371
372
373
# File 'lib/bundler/dsl.rb', line 371

def description
  @description
end

#dsl_pathString (readonly)

Returns the path of the dsl file that raised the exception.

Returns:

  • (String)

    the path of the dsl file that raised the exception.



375
376
377
# File 'lib/bundler/dsl.rb', line 375

def dsl_path
  @dsl_path
end

Instance Method Details

#contentsString

Returns the contents of the DSL that cause the exception to be raised.

Returns:

  • (String)

    the contents of the DSL that cause the exception to be raised.



401
402
403
404
405
# File 'lib/bundler/dsl.rb', line 401

def contents
  @contents ||= begin
    dsl_path && File.exist?(dsl_path) && File.read(dsl_path)
  end
end

#status_codeObject



394
395
396
# File 'lib/bundler/dsl.rb', line 394

def status_code
  @status_code || super
end

#to_sString

The message of the exception reports the content of podspec for the line that generated the original exception.

Examples:

Output


Invalid podspec at `RestKit.podspec` - undefined method
`exclude_header_search_paths=' for #<Pod::Specification for
`RestKit/Network (0.9.3)`>

    from spec-repos/master/RestKit/0.9.3/RestKit.podspec:36
    -------------------------------------------
        # because it would break: #import <CoreData/CoreData.h>
 >      ns.exclude_header_search_paths = 'Code/RestKit.h'
      end
    -------------------------------------------

Returns:

  • (String)

    the message of the exception.



425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/bundler/dsl.rb', line 425

def to_s
  @to_s ||= begin
    trace_line, description = parse_line_number_from_description

    m = "\n[!] "
    m << description
    m << ". Bundler cannot continue.\n"

    return m unless backtrace && dsl_path && contents

    trace_line = backtrace.find { |l| l.include?(dsl_path.to_s) } || trace_line
    return m unless trace_line
    line_numer = trace_line.split(':')[1].to_i - 1
    return m unless line_numer

    lines      = contents.lines.to_a
    indent     = ' #  '
    indicator  = indent.gsub('#', '>')
    first_line = (line_numer.zero?)
    last_line  = (line_numer == (lines.count - 1))

    m << "\n"
    m << "#{indent}from #{trace_line.gsub(/:in.*$/, '')}\n"
    m << "#{indent}-------------------------------------------\n"
    m << "#{indent}#{    lines[line_numer - 1] }" unless first_line
    m << "#{indicator}#{ lines[line_numer] }"
    m << "#{indent}#{    lines[line_numer + 1] }" unless last_line
    m << "\n" unless m.end_with?("\n")
    m << "#{indent}-------------------------------------------\n"
  end
end