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

evaluator.EvaluateOutputFiles fails when overriding output property #71

Open
amannm-apple opened this issue Jun 7, 2024 · 2 comments
Open

Comments

@amannm-apple
Copy link

evaluator EvaluateOutputFiles fails with the following error:

–– Pkl Error ––
Cannot find method `toMap` in class `Null`.

1 | output.files.toMap().mapValues((_, it) -> it.text)
    ^^^^^^^^^^^^^^^^^^^^
at  (repl:text)

Available methods in class `Null`:
getClass
ifNonNull
toString

when evaluating the following document:

output {
  value = (module.toDynamic()) {
    output = "foo"
  }
}
@bioball
Copy link
Contributor

bioball commented Jun 7, 2024

This happens because output.files, indeed, is null. However, perhaps we can return an empty map in this case.

@Carpe-Wang
Copy link

Carpe-Wang commented Jun 20, 2024

@bioball hey, Can I do this (we can return an empty map in this case.)?

func (e *evaluator) EvaluateOutputFiles(ctx context.Context, source *ModuleSource) (map[string]string, error) {
	var out map[string]string
	err := e.EvaluateExpression(ctx, source, "output.files.toMap().mapValues((_, it) -> it.text)", &out)
	return out, err
}

In above code I want use the

err := e.EvaluateExpression(ctx, source, `
		if output.files != null {
			output.files.toMap().mapValues((_, it) -> it.text)
		} else {
			{}
		}`, &out)

to replace err := e.EvaluateExpression(ctx, source, "output.files.toMap().mapValues((_, it) -> it.text)", &out) to achieve return an empty map in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants