How to resolve illegal character code U+0003

I am trying to run a nomad job that does a simple task of downloading a binary file from a remote repository. On running the job the nomad agent throws the error:

Failed Artifact Download  failed to download artifact
"https://domain/releases/path/to/lib/version/lib-1.5.3.jar": error downloading
'https://domain/releases/path/to/lib/version/lib-1.5.3.jar': XML syntax error on line 1: 
 illegal character code U+0003

Below is my job specification:

job "job" {
  datacenters = ["dc1"]
  type="batch"
  group "download" {
    task "binary" {
      driver = "exec"
      artifact {
        source = "https://domain/releases/path/to/lib/version/lib-1.5.3.jar"
        destination = "/path/to/dir" 
        mode = "dir"
      }
      resources {
        cpu = 50 
        memory = 10
      }
    }
  }
}

I have done some digging and apparently this error means I have a # somewhere which I have checked and there’s none. What could be the issue ?

The mode=dir flag is for downloading a directory. Removing the mode specifier or setting it to the default of “any” should resolve your issue. You can also use mode="file"and include the filename in the destination value—this is how you would rename a downloaded object.

I have created a GitHub issue, hashicorp/nomad #10388, to see if we can improve the documentation.

More information on the error itself

This is based on the underlying library’s ClientModeDir mode:

// ClientModeDir downloads a directory. In this mode, dst must be
// a directory path (doesn't have to exist). src must point to an
// archive or directory (such as in s3).

When go-getter has ClientModeDir set, it parses the response using an XML parser to find child objects. This parsing step is what generates the error you receive.

Hope this gets you unjammed,

-cv


Charlie Voiselle
Product Education Engineer - Nomad

Thank you Charlie for your prompt response.
The documentation is a bit unclear but I get the idea. Thanks for submitting the issue to your team.

Now I have corrected the job specification as you prescribed . Below is the job spec:

job "job" { 
  datacenters = ["dc1"] 
  type        =  "batch"
  group "download" {
    task "binary" {
      driver = "exec"
      artifact {
        source = "https://domain/releases/path/to/lib/version/lib-1.5.3.jar"
        destination = "/path/to/dir/lib-1.5.3.jar" 
        mode = "file"
      } 
	  config {
		  command = "ls"
          args = ["/path/to/dir/lib-1.5.3.jar"]
	  }
	  resources {
        cpu    = 50 
        memory = 10
      }
    }
  }
}

When I execute the job spec above it runs to completion however the desired goal is not met which is to download the artifact to the destination configured in the job spec.
what could be the problem ?

One possibility is that you are encountering a platform-specific behavior of the Java driver. On Linux, the java driver runs in an isolated chroot environment, so you can use absolute paths like you show above. In the case of Windows and macOS, the Java driver runs in an unisolated mode because they lack the chroot functionality. This difference can cause issues with absolute paths.

We just added a tutorial to Learn, Migrate a Java Application to Nomad (Linux/macOS or Windows) that demonstrates downloading a Jarfile with the artifact stanza into the task directory and referring to it via class path.

If possible, I recommend using the task folder to store job assets. This enables you to use a relative path to refer to the jarfile location. You can read more about Nomad’s allocation filesystem setup here - Filesystem | Nomad by HashiCorp. It’s a bit dense, but if you are loading files into your allocation it can be helpful to understand the bigger picture.

Further down on that page, there is a section devoted to Templates, Artifacts, and Dispatch Payloads, which can help explain the process and gotchas for cases where mounts are in use.

I have a tiny sample that demonstrates using the task’s local directory also.

Hopefully this helps!

-cv


Charlie Voiselle
Product Education Engineer, Nomad