{"record":{"id":"633145db27047b66","repo":"awesome-print/awesome_print","slug":"could-not-load-aprc-from-env-home-e","errorCode":null,"errorMessage":"Could not load '.aprc' from ENV['HOME']: #{e}","messagePattern":"Could not load '\\.aprc' from ENV\\['HOME'\\]: #(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/awesome_print/inspector.rb","lineNumber":166,"sourceCode":"      dotfile = File.join(ENV['HOME'], '.aprc')\n      load dotfile if dotfile_readable?(dotfile)\n    end\n\n    def dotfile_readable? dotfile\n      if @@dotfile_readable.nil? || @@dotfile != dotfile\n        @@dotfile_readable = File.readable?(@@dotfile = dotfile)\n      end\n      @@dotfile_readable\n    end\n    @@dotfile_readable = @@dotfile = nil\n\n    # Load ~/.aprc file with custom defaults that override default options.\n    #---------------------------------------------------------------------------\n    def merge_custom_defaults!\n      load_dotfile\n      merge_options!(AwesomePrint.defaults) if AwesomePrint.defaults.is_a?(Hash)\n    rescue => e\n      $stderr.puts \"Could not load '.aprc' from ENV['HOME']: #{e}\"\n    end\n  end\nend\n","sourceCodeStart":148,"sourceCodeEnd":170,"githubUrl":"https://github.com/awesome-print/awesome_print/blob/8a7ff0aabacbebf694c3e27242809219a96d5a3b/lib/awesome_print/inspector.rb#L148-L170","documentation":"AwesomePrint prints this warning to stderr when it cannot load or apply your personal config file ~/.aprc. Every ap/ai call builds an AwesomePrint::Inspector, whose initialize calls merge_custom_defaults!: it Ruby-`load`s #{ENV['HOME']}/.aprc (inspector.rb:148) and then merges AwesomePrint.defaults into the options. Any StandardError raised in that process — ENV['HOME'] being nil inside File.join, a runtime error while executing .aprc, or a :color default that is not a Hash making @options[:color].merge! raise TypeError — is rescued, the original exception is embedded via #{e}, and the library silently falls back to built-in defaults. Nothing crashes; your custom defaults are simply ignored (a pure Ruby syntax error in .aprc raises SyntaxError, which this rescue does not catch at all).","triggerScenarios":"Calling ap(anything) or object.ai in a process where ENV['HOME'] is nil (File.join(nil, '.aprc') raises TypeError: no implicit conversion of nil into String); a ~/.aprc whose Ruby raises StandardError when loaded, e.g. referencing an app constant undefined outside the app (NameError); AwesomePrint.defaults = { color: :blue } (non-Hash :color) making merge_options! at inspector.rb:140 call @options[:color].merge!(:blue) (TypeError); File.readable? raising Errno (EACCES/ENOENT) because $HOME points to an unreadable or stale path.","commonSituations":"CI runners, Docker containers, cron jobs, or systemd services where HOME is unset or scrubbed from the environment; a .aprc tuned inside a Rails console (referencing Rails/app constants) then used in plain ruby or irb; hand-edited .aprc with a typo or wrong defaults shape; shared dotfiles copied between machines with different users and permissions.","solutions":["Read the tail of the message: the #{e} part carries the real underlying exception (e.g. 'no implicit conversion of nil into String' or 'uninitialized constant') — fix that cause, not awesome_print.","Verify the dotfile standalone: ruby -c ~/.aprc for syntax, then ruby -e \"load File.expand_path('~/.aprc')\" to reproduce any runtime error outside your app.","If HOME is unset (CI/container/service), set it before any printing: export HOME in the CI config, or add ENV['HOME'] ||= Dir.home early in boot.","Fix the defaults shape — :color must be a nested Hash: AwesomePrint.defaults = { color: { string: :redish }, indent: -2 }.","Still unexplained? Rename ~/.aprc to ~/.aprc.bak and re-run; if the warning disappears, bisect the dotfile line by line."],"exampleFix":"# before (~/.aprc) — :color is a Symbol, merge_options! raises TypeError on every ap\nAwesomePrint.defaults = { color: :blue, indent: 2 }\n\n# after — :color is a Hash, loads cleanly\nAwesomePrint.defaults = { color: { string: :blue }, indent: 2 }","handlingStrategy":"validation","validationCode":"# Run once at boot, before the first ap/ai call\naprc = File.join(ENV['HOME'].to_s, '.aprc')\nif File.readable?(aprc)\n  RubyVM::InstructionSequence.compile_file(aprc) # surfaces SyntaxError early, with a line number\n  load aprc                                       # surfaces runtime errors now, not on every print\nend\nif AwesomePrint.defaults.is_a?(Hash) && AwesomePrint.defaults.key?(:color) && !AwesomePrint.defaults[:color].is_a?(Hash)\n  raise ArgumentError, 'AwesomePrint.defaults[:color] must be a Hash'\nend","typeGuard":"def valid_aprc_defaults?\n  d = AwesomePrint.defaults\n  d.nil? || (d.is_a?(Hash) && (d[:color].nil? || d[:color].is_a?(Hash)))\nend\n\nraise 'bad .aprc defaults shape' unless valid_aprc_defaults?","tryCatchPattern":null,"preventionTips":["Set HOME explicitly in CI, containers, cron, and systemd units (export HOME=/root), or guard boot with ENV['HOME'] ||= Dir.home.","Keep ~/.aprc to plain AwesomePrint.defaults assignments only; never reference app- or Rails-specific constants there.","After every .aprc edit, smoke-test it: ruby -c ~/.aprc && ruby -e \"load File.expand_path('~/.aprc')\".","Always nest :color as a Hash inside AwesomePrint.defaults, e.g. { color: { string: :redish } }."],"tags":["ruby","awesome-print","aprc","dotfile","home-env","configuration"],"backgroundTag":"config-file-load-failed","analyzedSha":"8a7ff0aabacbebf694c3e27242809219a96d5a3b","analyzedAt":"2026-08-23T02:33:16.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}