Skip to content

fix: clarify actor not found error when ID is explicitly provided - #1337

Open
kuntal1461 wants to merge 3 commits into
apify:masterfrom
kuntal1461:fix/actor-context-error-message
Open

fix: clarify actor not found error when ID is explicitly provided#1337
kuntal1461 wants to merge 3 commits into
apify:masterfrom
kuntal1461:fix/actor-context-error-message

Conversation

@kuntal1461

Copy link
Copy Markdown
Contributor

Closes #1147

What changed

  • Extracted formatActorContextError(reason, actorId) helper in resolve-actor-context.ts
  • When actorId is provided, error omits "run in an Actor directory / specify the Actor ID" suggestions and instead hints at token/permission access
  • When no actorId is provided, original fallback message is preserved
  • Applied to all four affected commands: actors info, builds create, builds ls, runs ls

Why

The old message suggested the user specify an Actor ID even when they already had — misleading when the real cause is a token with no access to an org Actor.

Test

  • Added unit tests for formatActorContextError in test/unit/lib/commands/resolve-actor-context.test.ts covering both the ID-provided and no-ID paths

Install size

No new dependencies added.

@kuntal1461
kuntal1461 force-pushed the fix/actor-context-error-message branch from a0081de to cc3bc54 Compare August 19, 2026 14:18
@kuntal1461

Copy link
Copy Markdown
Contributor Author

Hi @l2ysho, @DaveHanns, @patrikbraborec 👋

Just wanted to kindly check if you'd have a chance to review this PR when possible.

I'm happy to make any changes or address any feedback.

Thank you for your time!


export function formatActorContextError(reason: string, providedActorNameOrId?: string) {
if (providedActorNameOrId) {
return `${reason}. Check that the Actor ID or name is correct and that your API token has permission to access it.`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@patrikbraborec Are you ok with this message or you would like also mention organization as you do in a issue description?


import { getLocalConfig, getLocalUserInfo } from '../utils.js';

export function formatActorContextError(reason: string, providedActorNameOrId?: string) {

@l2ysho l2ysho Sep 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need to create helper function just for 2 occurrences (especially when we need to decide which to show inside). We are completely fine to have these 2 messages inline as original.

@l2ysho

l2ysho commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

@patrikbraborec btw similar problem also in builds ls, builds create, runs ls, maybe it is worth to fix all places, still feels pretty low priority

Remove formatActorContextError helper and inline the conditional message
directly at each call site in actors info, builds create, builds ls, and
runs ls. Drop the unit tests for the removed helper.
@kuntal1461
kuntal1461 force-pushed the fix/actor-context-error-message branch from cc3bc54 to aa99fbb Compare September 1, 2026 16:40
@kuntal1461

Copy link
Copy Markdown
Contributor Author

Thanks for the review @l2ysho!

Removed the formatActorContextError helper and inlined the conditional messages directly at each call site. Also dropped the unit tests for the removed helper.

Happy to adjust the error message wording once @patrikbraborec shares their thoughts on whether to mention the organization.

@kuntal1461
kuntal1461 requested a review from l2ysho September 1, 2026 17:12
@patrikbraborec

Copy link
Copy Markdown
Contributor

Thanks @kuntal1461. @szaganek - please can you review the text? Thanks!

@szaganek szaganek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd suggest rephrasing the first message and getting rid of please.

Comment thread src/commands/actors/info.ts Outdated
if (!ctx.valid) {
error({
message: `${ctx.reason}. Please specify the Actor ID.`,
message: `${ctx.reason}. Check that the Actor ID or name is correct and that your API token has permission to access it.`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
message: `${ctx.reason}. Check that the Actor ID or name is correct and that your API token has permission to access it.`,
message: `${ctx.reason}. Check that the ID or name is correct and that your API token has access to this Actor.`,

To avoid dangling it.

Comment thread src/commands/builds/create.ts Outdated
error({
message: `${ctx.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,
message: actorId
? `${ctx.reason}. Check that the Actor ID or name is correct and that your API token has permission to access it.`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
? `${ctx.reason}. Check that the Actor ID or name is correct and that your API token has permission to access it.`
? `${ctx.reason}. Check that the ID or name is correct and that your API token has access to this Actor.`

Comment thread src/commands/builds/create.ts Outdated
message: `${ctx.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,
message: actorId
? `${ctx.reason}. Check that the Actor ID or name is correct and that your API token has permission to access it.`
: `${ctx.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
: `${ctx.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,
: `${ctx.reason}. Run this command in an Actor directory, or specify the Actor ID.`,

Comment thread src/commands/builds/ls.ts Outdated
error({
message: `${ctx.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,
message: actorId
? `${ctx.reason}. Check that the Actor ID or name is correct and that your API token has permission to access it.`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
? `${ctx.reason}. Check that the Actor ID or name is correct and that your API token has permission to access it.`
? `${ctx.reason}. Check that the ID or name is correct and that your API token has access to this Actor.`

Comment thread src/commands/builds/ls.ts Outdated
message: `${ctx.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,
message: actorId
? `${ctx.reason}. Check that the Actor ID or name is correct and that your API token has permission to access it.`
: `${ctx.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
: `${ctx.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,
: `${ctx.reason}. Run this command in an Actor directory, or specify the Actor ID.`,

Comment thread src/commands/runs/ls.ts Outdated
error({
message: `${ctx.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,
message: actorId
? `${ctx.reason}. Check that the Actor ID or name is correct and that your API token has permission to access it.`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
? `${ctx.reason}. Check that the Actor ID or name is correct and that your API token has permission to access it.`
? `${ctx.reason}. Check that the ID or name is correct and that your API token has access to this Actor.`

Comment thread src/commands/runs/ls.ts Outdated
message: `${ctx.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,
message: actorId
? `${ctx.reason}. Check that the Actor ID or name is correct and that your API token has permission to access it.`
: `${ctx.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
: `${ctx.reason}. Please run this command in an Actor directory, or specify the Actor ID.`,
: `${ctx.reason}. Run this command in an Actor directory, or specify the Actor ID.`,

- Replace "Actor ID or name" with "ID or name" (redundant in context)
- Replace "permission to access it" with "has access to this Actor" (avoids dangling "it")
- Remove "Please" from the no-actorId fallback message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kuntal1461

Copy link
Copy Markdown
Contributor Author

Thanks @szaganek for the review!

Applied all suggestions:

  • Replaced Actor ID or name with ID or name (less redundant in context)
  • Replaced permission to access it with has access to this Actor (avoids the dangling "it")
  • Removed Please from the no-actorId fallback message

All four commands (actors info, builds create, builds ls, runs ls) are updated.

@kuntal1461
kuntal1461 requested a review from szaganek September 2, 2026 12:06
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.

Improve error message when Actor ID is provided but not found

5 participants