{"record":{"id":"1d6679f9cd217b27","repo":"alexreisner/geocoder","slug":"region-code-region-code-is-invalid-use-one-of-valid-region","errorCode":null,"errorMessage":"region_code '#{region_code}' is invalid. use one of #{valid_region_codes}.https://developer.trimblemaps.com/restful-apis/location/single-search/single-search-api/#test-the-api-now","messagePattern":"region_code '#(.+?)' is invalid\\. use one of #(.+?)\\.https://developer\\.trimblemaps\\.com/restful-apis/location/single-search/single-search-api/#test-the-api-now","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"lib/geocoder/lookups/pc_miler.rb","lineNumber":30,"sourceCode":"      # EU: Europe\n      # ME: Middle East\n      # MX: Mexico\n      # NA: North America\n      # OC: Oceania\n      # SA: South America\n      %w[AF AS EU ME MX NA OC SA]\n    end\n\n    def name\n      \"PCMiler\"\n    end\n\n    private # ---------------------------------------------------------------\n\n    def base_query_url(query)\n      region_code = region(query)\n      if !valid_region_codes.include?(region_code)\n        raise \"region_code '#{region_code}' is invalid. use one of #{valid_region_codes}.\" \\\n          \"https://developer.trimblemaps.com/restful-apis/location/single-search/single-search-api/#test-the-api-now\"\n      end\n\n      \"#{protocol}://singlesearch.alk.com/#{region_code}/api/search?\"\n    end\n\n    def results(query)\n      return [] unless data = fetch_data(query)\n      if data['Locations']\n        add_metadata_to_locations!(data)\n        data['Locations']\n      else\n        []\n      end\n    end\n\n    def add_metadata_to_locations!(data)\n      confidence = data['QueryConfidence']","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/alexreisner/geocoder/blob/c10bd701215110ebe65da1c8b8b410b124208fd2/lib/geocoder/lookups/pc_miler.rb#L12-L48","documentation":"The PC*MILER lookup (Trimble Maps Single-Search API) only supports a fixed set of region codes (e.g. NA, EU, OC, SA). The lookup validates the region via valid_region_codes before building the request URL, and raises a plain RuntimeError if the configured region (from Geocoder config or the query) is not one of them.","triggerScenarios":"Calling Geocoder.search(address, lookup: :pc_miler) or configuring Geocoder.configure(lookup: :pc_miler, pc_miler: {region: ...}) with a region code not in valid_region_codes (e.g. 'us', 'north_america', or a typo like 'N.A.').","commonSituations":"Default geocoder config left unset so region(query) returns nil; using lowercase or full-name region strings instead of the API's uppercase codes; copying config from another Trimble API that uses different region identifiers; region param passed per-query in the wrong form.","solutions":["Set a valid region code in config: Geocoder.configure(pc_miler: {region: 'NA'}) (see valid_region_codes in lib/geocoder/lookups/pc_miler.rb for the exact accepted list).","Use the exact uppercase codes supported by the Trimble Single-Search API (NA, EU, OC, SA, etc.) rather than lowercase or full names.","If passing region per query, ensure the query options include the correct region value the lookup's region(query) method reads.","Verify the gem version's supported regions — Trimble has changed the API over time, so check the linked Single-Search API docs."],"exampleFix":"// before\nGeocoder.configure(lookup: :pc_miler, pc_miler: { region: 'usa' })\n// after\nGeocoder.configure(lookup: :pc_miler, pc_miler: { region: 'NA' })","handlingStrategy":"validation","validationCode":"VALID_REGIONS = %w[NA EU OC SA].freeze # mirror valid_region_codes from lib/geocoder/lookups/pc_miler.rb\nregion = Geocoder.config[:pc_miler][:region]\nraise ArgumentError, \"pc_miler region #{region.inspect} invalid; use one of #{VALID_REGIONS}\" unless VALID_REGIONS.include?(region)","typeGuard":null,"tryCatchPattern":"begin\n  Geocoder.search(address, lookup: :pc_miler)\nrescue RuntimeError => e\n  raise unless e.message.start_with?('region_code')\n  Rails.logger.error(\"PC*MILER region misconfigured: #{e.message}\")\n  fallback_lookup_results\nend","preventionTips":["Mirror valid_region_codes from the lookup file in your config validation at boot (e.g. an initializer asserting the region is valid).","Always use the uppercase Trimble region codes (NA, EU, OC, SA), never lowercase or full names.","Configure the region explicitly in Geocoder.configure instead of relying on defaults.","Pin and review gem versions when Trimble updates its API, and re-check the linked docs for the current region list."],"tags":["geocoding","configuration","runtime-error","ruby"],"backgroundTag":"invalid-enum-value","analyzedSha":"c10bd701215110ebe65da1c8b8b410b124208fd2","analyzedAt":"2026-09-15T23:43:32.125Z","contentChangedAt":"2026-09-15T23:43:32.125Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}