Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using undefined variables in task config produces useless error #5694

Closed
schmichael opened this issue May 13, 2019 · 1 comment · Fixed by #5844
Closed

Using undefined variables in task config produces useless error #5694

schmichael opened this issue May 13, 2019 · 1 comment · Fixed by #5844

Comments

@schmichael
Copy link
Member

Nomad version

0.9.0 and 0.9.1

Issue

Using an undefined variable for interpolation in a task config stanza produces a useless error message. For example ${FOO_bar} in a Docker dns_servers list would cause the following error:

2019-05-13T15:16:19.293-0700 [ERROR] client.alloc_runner.task_runner: running driver failed: alloc_id=dd29e024-3b05-0575-0deb-745676003cf5 task=redis error="failed to decode driver config: [pos 298]: readContainerLen: Unrecognized descriptor byte: hex: d4, decimal: 212"

The root cause seems to be that undefined variables are defined as Unknown in HCL2:

"labels":[]interface {}{map[string]interface {}{"foo":cty.unknown}}

Reproduction steps

Use an undefined variable in a task config.

Job file (if appropriate)

job "example" {
  datacenters = ["dc1"]

  group "cache" {
    task "redis" {
      driver = "docker"

      config {
        image = "redis:3.2"
        port_map {
          db = 6379
        }
        labels {
          foo = "${INVALID_bar}"
        }
      }

      resources {
        cpu    = 500
        memory = 256
        network {
          mbits = 10
          port "db" {}
        }
      }
    }
  }
}
notnoop pushed a commit to hashicorp/hcl2 that referenced this issue Jun 17, 2019
Fix a bug where diagnostics found when evaluating array individual
elements are ignored, resulting in suppressed errors.

Nomad observed this issue in hashicorp/nomad#5694.
notnoop pushed a commit to hashicorp/hcl2 that referenced this issue Jun 17, 2019
Fix a bug where diagnostics found when evaluating array individual
elements are ignored, resulting in suppressed errors.

Nomad observed this issue in hashicorp/nomad#5694.
notnoop pushed a commit that referenced this issue Jun 17, 2019
This upgrades hcl2 library dependency to pick up
hashicorp/hcl2#113 .

Prior to this change, parsing and decoding array attributes containing
invalid errors (e.g. references to unknown variables) are silently
dropped, with `cty.Unknown` being assigned to the bad element.  Rather
than showing a type/meaningful error from hcl2, we get a very decrypted
error message from msgpack layer trying to handle `cty.unknown`.

This ensures that we propagate diagnostics correctly and report
meaningful errors to users.

Fixes #5694
Fixes #5680
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant