Skip to content

Incorrect Parameters For Command With Same Name As Job #191

@dsanders11

Description

@dsanders11

If a command and a job have the same name, the language server will use the parameters from the job, for the command's parameters, leading to incorrect errors.

It looks like the root cause are these chunks of code, where the parameters are looked up for a command first, then a job, so if they have the same name, it falls through and returns the parameters for the job. It looks like that code needs to have a better understanding of what type the entity actually is, rather than just looking it up by name, since the name can refer to either a command or a job.

Warning

This issue exists in at least two spots, GetDefinedParams and GetOrbDefinedParams, but I did not exhaustively check for others. I'm seeing this error specifically with commands from an orb.

func (doc *YamlDocument) GetDefinedParams(entityName string, cache *utils.Cache) map[string]ast.Parameter {
var definedParams map[string]ast.Parameter
if command, ok := doc.Commands[entityName]; ok {
definedParams = command.Parameters
}
if job, ok := doc.Jobs[entityName]; ok {
definedParams = job.Parameters
}
if doc.IsOrbCommand(entityName, cache) || doc.IsOrbJob(entityName, cache) {
return doc.GetOrbDefinedParams(entityName, cache)
}
return definedParams
}

func (doc *YamlDocument) GetOrbDefinedParams(entityName string, cache *utils.Cache) map[string]ast.Parameter {
var definedParams map[string]ast.Parameter
splittedName := strings.Split(entityName, "/")
orbName := splittedName[0]
commandOrJob := splittedName[1]
orbInfo, err := doc.GetOrFetchOrbInfo(doc.Orbs[orbName], cache)
if err != nil {
return definedParams
}
if command, ok := orbInfo.Commands[commandOrJob]; ok {
definedParams = command.Parameters
}
if job, ok := orbInfo.Jobs[commandOrJob]; ok {
definedParams = job.Parameters
}
return definedParams
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions