{"record":{"id":"0280c4c04dbd37fa","repo":"apple/pkl","slug":"invalidurimissingfragment","errorCode":"invalidUriMissingFragment","errorMessage":"invalidUriMissingFragment","messagePattern":"invalidUriMissingFragment","errorType":"error_code","errorClass":"URISyntaxException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/packages/PackageAssetUri.java","lineNumber":65,"sourceCode":"      this.uri = new URI(base.getScheme(), base.getSchemeSpecificPart(), assetPath);\n    } catch (URISyntaxException e) {\n      // impossible condition, we have a valid URI to start with.\n      throw PklBugException.unreachableCode();\n    }\n    this.packageUri = packageUri;\n    this.assetPath = assetPath;\n  }\n\n  public PackageAssetUri(String uri) throws URISyntaxException {\n    this(new URI(uri));\n  }\n\n  public PackageAssetUri(URI uri) throws URISyntaxException {\n    this.uri = uri;\n    this.packageUri = new PackageUri(uri);\n    var fragment = uri.getFragment();\n    if (fragment == null) {\n      throw new URISyntaxException(\n          uri.toString(), ErrorMessages.create(\"invalidUriMissingFragment\", uri));\n    }\n    if (!fragment.startsWith(\"/\")) {\n      throw new URISyntaxException(\n          uri.toString(), ErrorMessages.create(\"cannotHaveRelativeFragment\", fragment, uri));\n    }\n    this.assetPath = fragment;\n  }\n\n  public URI getUri() {\n    return uri;\n  }\n\n  public PackageUri getPackageUri() {\n    return packageUri;\n  }\n\n  public String getAssetPath() {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/packages/PackageAssetUri.java#L47-L83","documentation":"PackageAssetUri requires package asset URIs to carry a fragment identifying the asset path (e.g. package://host/pkg@1.0.0#/gen/my.pkl). The constructor throws URISyntaxException with message key invalidUriMissingFragment when the URI has no fragment at all, because without it the asset being referenced is undefined.","triggerScenarios":"Constructing new PackageAssetUri(URI) with a fragment-less URI such as package://example.com/my/pkg@1.0.0 — e.g. an import string missing the '#/path' part, or a URI stripped of its fragment by earlier processing.","commonSituations":"Typo in a package import statement (omitting the #/file.pkl part), a tool that URL-normalized the URI and dropped the empty/absent fragment, or copying a package URI without its asset path.","solutions":["Append the asset path fragment to the URI: package://host/pkg@1.0.0#/path/to/file.pkl","Check the import/URI string for a missing # character or truncated fragment","Verify no intermediate code calls uri.normalize()/strip that removes the fragment before constructing PackageAssetUri"],"exampleFix":"// before\nnew PackageAssetUri(URI.create(\"package://example.com/pkg@1.0.0\"));\n// after\nnew PackageAssetUri(URI.create(\"package://example.com/pkg@1.0.0#/gen/pkg.pkl\"));","handlingStrategy":"validation","validationCode":"boolean hasFragment(URI uri) { return uri.getFragment() != null; }\n// run before: new PackageAssetUri(uri)","typeGuard":"static PackageAssetUri safeCreate(URI uri) throws URISyntaxException {\n  if (uri.getFragment() == null) throw new IllegalArgumentException(\"package URI needs #/assetPath fragment: \" + uri);\n  return new PackageAssetUri(uri);\n}","tryCatchPattern":"try {\n  var u = new PackageAssetUri(uri);\n} catch (URISyntaxException e) {\n  if (e.getReason().contains(\"fragment\")) {\n    log.error(\"Package URI is missing its #/asset fragment: \" + e.getInput(), e);\n  }\n}","preventionTips":["Always write package URIs with the #/path fragment (e.g. package://host/pkg@1.0.0#/gen/pkg.pkl)","Check imports for a missing '#' or truncated fragment","Avoid URI normalization steps that drop fragments"],"tags":["pkl","uri","missing-fragment"],"backgroundTag":"invalid-url-format","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}