hasura/graphql-engine · error

error in reading %s file: %w

Error message

error in reading %s file: %w

What it means

Thrown by Actions.Create when the actions.graphql file cannot be read while creating a new action. GetActionsGraphQLFileContent failed (file missing or unreadable), and the error wraps the graphql file name with the underlying cause.

Source

Thrown at cli/internal/metadataobject/actions/actions.go:79

	}

	return cfg
}

func (a *ActionConfig) Create(name string, introSchema any, deriveFrom string) error {
	var op errors.Op = "actions.ActionConfig.Create"

	err := a.ensureCliExt()
	defer a.cleanupCliExt()

	if err != nil {
		return errors.E(op, err)
	}

	// Read the content of graphql file
	graphqlFileContent, err := a.GetActionsGraphQLFileContent()
	if err != nil {
		return errors.E(op, fmt.Errorf("error in reading %s file: %w", graphqlFileName, err))
	}
	// Read actions.yaml
	oldAction, err := a.GetActionsFileContent()
	if err != nil {
		return errors.E(op, fmt.Errorf("error in reading %s file: %w", a.Filename(), err))
	}
	// check if action already present
	for _, currAction := range oldAction.Actions {
		if currAction.Name == name {
			return errors.E(op, fmt.Errorf("action %s already exists in %s", name, graphqlFileName))
		}
	}

	var defaultSDL string
	if introSchema == nil {
		defaultSDL = `type Mutation {
	# Define your action as a mutation here
	` + name + ` (arg1: SampleInput!): SampleOutput

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Ensure actions.graphql exists in the configured metadata/actions directory
  2. Run `hasura actions use-codegen` / create the file scaffold before calling Create
  3. Verify the metadata directory path in config matches where the file lives
  4. Check file read permissions
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(filepath.Join(metadataDir, "actions", "actions.graphql")); err != nil {
	// scaffold the file or run `hasura actions use-codegen` before Create
}

Try / catch

if err := actions.Create(name, derive, introSchema, dryRun); err != nil {
	if strings.Contains(err.Error(), "error in reading actions.graphql") {
		// create the missing scaffold, then retry
	}
	return err
}

Prevention

When it happens

Trigger: Running action creation (`hasura actions create X`) when actions.graphql is absent from the metadata directory, the metadata directory path is misconfigured, or the file has permissions that block reading.

Common situations: Fresh project where `hasura actions codegen` hasn't been initialized, custom metadata directory where actions.graphql wasn't created, or CI environments with restricted file permissions.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/da7b93a4be49a3f4. Report an issue: GitHub.