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

Improve Error Messaging for Actions by Using ExecutionContext's FileTable as Single Source of Truth and by Passing FileID to All Children Tokens. #564

Merged
merged 64 commits into from
Jul 8, 2020

Conversation

ethanchewy
Copy link
Contributor

@ethanchewy ethanchewy commented Jun 23, 2020

Branched off from: #557

This PR enables file names to be included in action error messages.

Our goal is to ensure that the fileIDs are associated with all the children tokens in the action.yml so that error messages reference the correct action file to allow for easier debugging. Also, we want to make sure that the FileTable is updated correctly throughout the process to ensure that Error messages will reference always the correctly associated file.

In this PR, we also refactor the code in ActionManifestManager to allow for passing fileIDs to the children tokens. Originally, there was a _fileTable attribute for ActionManifestManager instances as well as a FileTable for ExecutionContext instances. To reduce confusion and potential bugs in the future when we have nested actions, we refactored how the FileTable is used so that only ExecutionContext.FileTable is referenced. In the ActionManifestManager to ensure that only 1 fileTable (aka the ExecutionContext's fileTable) is referenced. Moreover, we add functionality to ensure that the FileTable is updated every time we load an Action yaml.

tl;dr ExecutionContext's FileTable is now the "source of truth" for any filetable related matters.

Demos:

=> Before error message: https://github.com/ethanchewy/testing-actions/actions/runs/144061679
(Line: 13, Col: 11): Unexpected value 'run:::::'
=> After PR error message: https://github.com/ethanchewy/testing-actions/actions/runs/145235133
ethanchewy/testing-composite-errors/v3/action.yml (Line: 13, Col: 11): Unexpected value 'run:::::'

More demos:
action.yml

runs:
    using: "composite"
    steps: 
        - run: echo ${{ fromJson("not json") }}

Error Messaging after delayed evaluation:
https://github.com/ethanchewy/testing-actions/actions/runs/145233958
ethanchewy/testing-composite-errors/v4/action.yml (Line: 13, Col: 16): Unexpected symbol: '"not'. Located at position 10 within expression: fromJson("not json"))

@ethanchewy
Copy link
Contributor Author

ethanchewy commented Jun 23, 2020

TODO: git pull master after merging the Composite Run Steps PR or git pull origin users/ethanchewy/compositetest2
Done.

@ethanchewy
Copy link
Contributor Author

ethanchewy commented Jun 23, 2020

TODO: Test with error messages such as {{ fromJson('not json') }}
Done.

@ethanchewy ethanchewy changed the title (IN PROGRESS) Pass FileId to Children Tokens and Only Use Execution Context's FileTable in ActionManifestManager (IN PROGRESS) Add Action File Info in ActionManifestManager and Pass Related FileID to Children Nodes for Better Error Messaging Jun 23, 2020
// Clean up file name real quick
// Instead of using Regex which can be computationally expensive,
// we can just remove the # of characters from the fileName according to the length of the basePath
string basePath = _hostContext.GetDirectory(WellKnownDirectory.Actions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HostContext.GetDirectory()

{
Trace.Error($"Action.yml load error: {error.Message}");
executionContext.Error(error.Message);
}

throw new ArgumentException($"Fail to load {manifestFile}");
throw new ArgumentException($"Fail to load {fileName}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this always shows actions.yml?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO for ethan: Change variable name top a more clear name

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline, it's the relative path. Would it help to name the variable relative___?

@@ -31,7 +31,6 @@ internal partial class TemplateEvaluator
Boolean omitHeader = false)
{
TemplateToken result;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undo this. 😆

@@ -160,13 +160,20 @@ public class PipelineTemplateEvaluator
}

public List<ActionStep> LoadCompositeSteps(
TemplateToken token)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to copy this change back to server.

var fileId = templateContext.GetFileId(fileName);

// Add this file to the FileTable in executionContext
executionContext.FileTable.Add(fileName);
Copy link
Collaborator

@ericsciple ericsciple Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After you add the "fileName" the fileId should match executionContext.FileTable.Length

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only add if new

@@ -297,7 +311,8 @@ public ActionDefinitionData Load(IExecutionContext executionContext, string mani
private ActionExecutionData ConvertRuns(
IExecutionContext executionContext,
TemplateContext context,
TemplateToken inputsToken)
TemplateToken inputsToken,
Int32 fileID)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used?

@@ -291,7 +291,7 @@ public async Task RunAsync(ActionRunStage stage)
// Error
if (exitCode != 0)
{
ExecutionContext.Error($"Process completed with exit code {exitCode}.");
ExecutionContext.Error($"Process completed with exit code {exitCode}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -160,13 +160,20 @@ public class PipelineTemplateEvaluator
}

public List<ActionStep> LoadCompositeSteps(
TemplateToken token)
TemplateToken token,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont forget to revert this

@ethanchewy ethanchewy changed the base branch from users/ethanchewy/compositeenv to master July 8, 2020 15:21
@ethanchewy ethanchewy changed the base branch from master to users/ethanchewy/compositeenv July 8, 2020 15:21
@ethanchewy ethanchewy changed the base branch from users/ethanchewy/compositeenv to master July 8, 2020 15:31

// Add this file to the FileTable in executionContext if it hasn't been added already
// we use > since fileID is 1 indexed
if (fileId > executionContext.FileTable?.Count)
Copy link
Collaborator

@ericsciple ericsciple Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need FileTable? anymore, or should this just be FileTable now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we don't need it anymore since the FileTable should always be non null. Will update this to executionContext.FileTable.Count.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch -ty

// Add the file table
if (_fileTable?.Count > 0)
// Add the file table from the Execution Context
if (executionContext.FileTable?.Count > 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question here, i think we can drop the ? now

@ethanchewy ethanchewy merged commit 9d7bd47 into master Jul 8, 2020
AdamOlech pushed a commit to antmicro/runner that referenced this pull request Jan 28, 2021
…able as Single Source of Truth and by Passing FileID to All Children Tokens. (actions#564)

* Composite Action Run Steps

* Env Flow => Able to get env variables and overwrite current env variables => but it doesn't 'stick'

* clean up

* Clean up trace messages + add Trace debug in ActionManager

* Add debugging message

* Optimize runtime of code

* Change String to string

* Add comma to Composite

* Change JobSteps to a List, Change Register Step function name

* Add TODO, remove unn. content

* Remove unnecessary code

* Fix unit tests

* Fix env format

* Remove comment

* Remove TODO message for context

* Add verbose trace logs which are only viewable by devs

* Initial Start for FileTable stuff

* Progress towards passing FileTable or FileID or FileName

* Sort usings in Composite Action Handler

* Change 0 to location

* Update context variables in composite action yaml

* Add helpful error message for null steps

* Pass fileID to all children token of root action token

* Change confusing term context => templateContext, Eliminate _fileTable and only use ExecutionContext.FileTable + update this table when need be

* Remove unnessary FileID attribute from CompositeActionExecutionData

* Clean up file path for error message

* Remove todo

* Fix Workflow Step Env overiding Parent Env

* Remove env in composite action scope

* Clean up

* Revert back

* revert back

* add back envToken

* Remove unnecessary code

* Add file length check

* Clean up

* Figure out how to handle set-env edge cases

* formatting

* fix unit tests

* Fix windows unit test syntax error

* Fix period

* Sanity check for fileTable add + remove unn. code

* revert back

* Add back line break

* Fix null errors

* Address situation if FileTable is null + add sanity check for adding file to fileTable

* add line

* Revert

* Fix unit tests to instantiate a FileTable

* Fix logic for trimming manifestfile path

* Add null check

* Add filetable to testing file, remove ? since we know filetable should never be non null
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

Successfully merging this pull request may close these issues.

3 participants