Exception: ViteRuby::MissingEntrypointError

Inherits:
Error
  • Object
show all
Defined in:
lib/vite_ruby/missing_entrypoint_error.rb

Overview

Internal: Raised when an entry is not found in the build manifest.

NOTE: The complexity here is justified by the improved usability of providing a more specific error message depending on the situation.

Constant Summary collapse

FAILED_BUILD_CAUSES =
<<~MSG
    - The last build failed. Try running `bin/vite build --clear --mode=:mode:` manually and check for errors.

  Errors:
  :errors:
MSG
DEFAULT_CAUSES =
<<-MSG
- The file path is incorrect.
- The file is not in the entrypoints directory.
- Some files are outside the sourceCodeDir, and have not been added to watchAdditionalPaths.
MSG
NO_AUTO_BUILD_CAUSES =
<<-MSG
- You have not run `bin/vite dev` to start Vite, or the dev server is not reachable.
- "autoBuild" is set to `false` in your config/vite.json for this environment.
MSG

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Error

#message

Constructor Details

#initialize(file_name:, last_build:, manifest:, config:) ⇒ MissingEntrypointError

Returns a new instance of MissingEntrypointError.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/vite_ruby/missing_entrypoint_error.rb', line 10

def initialize(file_name:, last_build:, manifest:, config:)
  @file_name, @last_build, @manifest, @config = file_name, last_build, manifest, config
  super <<~MSG
    Vite Ruby can't find #{file_name} in the manifests.

    Possible causes:
    #{possible_causes(last_build)}
    :troubleshooting:
    #{"Manifest files found:\n#{config.manifest_paths.map { |path| "  #{path.relative_path_from(config.root)}" }.join("\n")}\n" if last_build.success}
    #{"Content in your manifests:\n#{JSON.pretty_generate(manifest)}\n" if last_build.success}
    #{"Last build in #{config.mode} mode:\n#{last_build.to_json}\n" if last_build.success}
  MSG
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/vite_ruby/missing_entrypoint_error.rb', line 8

def config
  @config
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



8
9
10
# File 'lib/vite_ruby/missing_entrypoint_error.rb', line 8

def file_name
  @file_name
end

#last_buildObject (readonly)

Returns the value of attribute last_build.



8
9
10
# File 'lib/vite_ruby/missing_entrypoint_error.rb', line 8

def last_build
  @last_build
end

#manifestObject (readonly)

Returns the value of attribute manifest.



8
9
10
# File 'lib/vite_ruby/missing_entrypoint_error.rb', line 8

def manifest
  @manifest
end

Instance Method Details

#possible_causes(last_build) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vite_ruby/missing_entrypoint_error.rb', line 24

def possible_causes(last_build)
  if last_build.success == false
    FAILED_BUILD_CAUSES
      .sub(":mode:", config.mode)
      .sub(":errors:", last_build.errors.to_s.gsub(/^(?!$)/, "  "))
  elsif config.auto_build
    DEFAULT_CAUSES
  else
    DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
  end
end