Skip to content

Refactor error messages#5223

Open
AryamanSharma14 wants to merge 7 commits intodevelopfrom
refactor-error-messages
Open

Refactor error messages#5223
AryamanSharma14 wants to merge 7 commits intodevelopfrom
refactor-error-messages

Conversation

@AryamanSharma14
Copy link
Copy Markdown
Collaborator

No description provided.

@AryamanSharma14 AryamanSharma14 force-pushed the refactor-error-messages branch 2 times, most recently from c689b9e to ecafda8 Compare February 20, 2026 11:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors and expands several user-facing frappe.throw(...) messages across the Press API to be more descriptive and (in some cases) include documentation links.

Changes:

  • Updated multiple API validation/permission error messages to be more actionable and consistent.
  • Added documentation links to some error messages (Google OAuth, SaaS login flow, bench operations, asset store credentials).
  • Minor cleanup/formatting (e.g., removed legacy encoding header, adjusted function formatting).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
press/api/google.py Improves Google OAuth-related error messages; adds doc link for missing credentials.
press/api/email.py Makes analytics request validation error more specific.
press/api/developer/saas.py Makes SaaS login flow errors more actionable; adds “Learn more” links.
press/api/dashboard.py Improves tag duplication error message.
press/api/central.py Refines signup/trial validation errors and fixes a typo in “Country field”.
press/api/billing.py Tweaks invoice download permission error wording.
press/api/bench.py Refines multiple bench/deploy/dependency validation messages; adds doc links.
press/api/assets.py Improves asset upload/build-token errors; adds doc link for build token requirement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 228 to 230
frappe.throw(
"Sorry, you cannot login with this method as 2FA is enabled. Please visit https://frappecloud.com/dashboard to login."
"Sorry, you cannot login with this method as 2FA is enabled. Please visit https://frappecloud.com/dashboard to login.<a href='https://docs.frappe.io/cloud/two-factor-authentication-2fa' target='_blank'>Learn more</a>"
)
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

This message embeds a target="_blank" external link. Add rel="noopener noreferrer" to prevent reverse-tabnabbing, and add a space before the tag so the rendered text doesn’t run together ("login.<a ...").

Copilot uses AI. Check for mistakes.
Comment on lines +239 to +241
frappe.throw(
"Only SaaS sites are allowed to login to Frappe Cloud via this method.<a href='https://docs.frappe.io/cloud/simplified-login-to-frappe-cloud-dashboard' target='_blank'>Learn more</a>"
)
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

This message embeds a target="_blank" external link. Add rel="noopener noreferrer" to prevent reverse-tabnabbing, and add a space before the tag so the rendered text doesn’t run together ("method.<a ...").

Copilot uses AI. Check for mistakes.
if len(rg.dependencies) != len(dependencies):
frappe.throw("Need all required dependencies")
frappe.throw(
"All required dependencies must be provided. <a href='https://docs.frappe.io/cloud/common-issues/required-app-not-found' target='_blank'>Learn more</a>"
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

Changing this exception text will break existing API tests that assert on the old substring (e.g. press/api/tests/test_bench.py expects "Need all required dependencies"). Update the tests accordingly, or keep the previous phrase in the new message so assertions remain stable.

Suggested change
"All required dependencies must be provided. <a href='https://docs.frappe.io/cloud/common-issues/required-app-not-found' target='_blank'>Learn more</a>"
"Need all required dependencies. All required dependencies must be provided. <a href='https://docs.frappe.io/cloud/common-issues/required-app-not-found' target='_blank'>Learn more</a>"

Copilot uses AI. Check for mistakes.
if not re.match(r"^\d+\.\d+\.*\d*$", new["value"]):
frappe.throw(f"Invalid version for {new['key']}")
frappe.throw(
f"Invalid version format for {new['key']}. Expected X.Y.Z (e.g., 14.0.0). <a href='https://docs.frappe.io/cloud/common-issues/incompatible-app-version' target='_blank'>Learn more</a>"
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The validation uses regex ^\d+.\d+.\d$, which accepts versions like "3.6" as well as "3.6.0". The updated error message claims it expects X.Y.Z, which is inaccurate given the current validation; either tighten the regex to require 3 segments or adjust the message to match what’s accepted.

Suggested change
f"Invalid version format for {new['key']}. Expected X.Y.Z (e.g., 14.0.0). <a href='https://docs.frappe.io/cloud/common-issues/incompatible-app-version' target='_blank'>Learn more</a>"
f"Invalid version format for {new['key']}. Expected X.Y or X.Y.Z (e.g., 14.0 or 14.0.0). <a href='https://docs.frappe.io/cloud/common-issues/incompatible-app-version' target='_blank'>Learn more</a>"

Copilot uses AI. Check for mistakes.
Comment on lines +770 to +773
frappe.throw(
"Bench can only be deployed by the bench owner. <a href='https://docs.frappe.io/cloud/role-permissions' target='_blank'>Learn more</a>",
exc=frappe.PermissionError,
)
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

New/updated error messages in this file embed external links with target="_blank". Add rel="noopener noreferrer" to these anchors to prevent reverse-tabnabbing (applies to other similar links introduced in this file).

Copilot uses AI. Check for mistakes.
if not build_token:
frappe.throw("Build token is required to access asset store credentials", frappe.PermissionError)
frappe.throw(
"Build token is required to access asset store credentials. <a href='https://docs.frappe.io/cloud/local-fc-setup' target='_blank'>Learn more</a>",
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

This error message embeds an external link with target="_blank". Add rel="noopener noreferrer" to the anchor to prevent reverse-tabnabbing.

Suggested change
"Build token is required to access asset store credentials. <a href='https://docs.frappe.io/cloud/local-fc-setup' target='_blank'>Learn more</a>",
"Build token is required to access asset store credentials. <a href='https://docs.frappe.io/cloud/local-fc-setup' target='_blank' rel='noopener noreferrer'>Learn more</a>",

Copilot uses AI. Check for mistakes.
if team_name and not team_enabled:
frappe.throw(_("Account {0} has been deactivated").format(email))
frappe.throw(
_("Account {0} has been deactivated. Please contact support to reactivate your account. ").format(
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The translated deactivation error message has a trailing space at the end of the sentence, which can lead to awkward formatting (e.g., double-spaces when concatenated/rendered). Trim the trailing whitespace in the string literal.

Suggested change
_("Account {0} has been deactivated. Please contact support to reactivate your account. ").format(
_("Account {0} has been deactivated. Please contact support to reactivate your account.").format(

Copilot uses AI. Check for mistakes.
frappe.throw("google_credentials not found in site_config.json")
frappe.throw(
"Google credentials not found in site_config.json. Please configure Google OAuth credentials for your site. "
'<a href="https://docs.frappe.io/framework/user/en/integration/google_drive" target="_blank">Learn more</a>'
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

This error message embeds an external link with target="_blank". To avoid reverse-tabnabbing, add rel="noopener noreferrer" to the anchor (this file includes similar external links).

Suggested change
'<a href="https://docs.frappe.io/framework/user/en/integration/google_drive" target="_blank">Learn more</a>'
'<a href="https://docs.frappe.io/framework/user/en/integration/google_drive" target="_blank" rel="noopener noreferrer">Learn more</a>'

Copilot uses AI. Check for mistakes.
Comment on lines +405 to +409
frappe.throw(
"Invalid dependencies: "
+ ", ".join(diff)
+ ". <a href='https://docs.frappe.io/cloud/common-issues/incompatible-dependency-version' target='_blank'>Learn more</a>"
)
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.

Fix tests for this as well.

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.

4 participants