Back to Codeberg

"unexpected status code 400 Bad Request" when creating a PR #381

forgejo-contrib-forgejo-cli-issues-381.md

latest23.5 KB
Original Source

forgejo-contrib/forgejo-cli

Watch20

Star402

Fork

You've already forked forgejo-cli

51

CodeIssues 44Pull requests 8Releases 11Packages 2WikiActivity

"unexpected status code 400 Bad Request" when creating a PR #381

New issue

Closed

opened 2026-03-21 17:27:52 +01:00 by vasudan · 14 comments

vasudan commented 2026-03-21 17:27:52 +01:00

Copy link

Expected Behavior

When creating a PR using this:

fj pr create "My PR"

I expect it to create a PR, and if it fails tell me the reason that it failed

Actual Behavior

running this: fj pr create "My PR"

yields this:

text
Error: unexpected status code 400 Bad Request

Location:
    /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/forgejo-cli-0.4.0/src/prs.rs:981:40

Since its a 400 its probably something to do with the parameters, but I can't find a way to print out the response body in order to find out what the actual problem is.


I did enable trace logging on my forgejo instance to try to find out what was happening from the other side, but I don't see anything helpful:

text
2026/03/21 12:25:33 ...s/process/manager.go:204:Add() [T] Start 69bec67d: GET: /api/v1/repos/vasudan/my-repo? (request)
2026/03/21 12:25:33 ...eb/routing/logger.go:47:func1() [T] router: started GET /api/v1/repos/vasudan/my-repo? for 10.0.3.177:0
2026/03/21 12:25:33 ...vices/auth/oauth2.go:221:Verify() [T[] OAuth2 Authorization: Found token for user[3]
2026/03/21 12:25:33 ...vices/auth/oauth2.go:231:Verify() [T] OAuth2 Authorization: Logged in user <User 3:my-user>
2026/03/21 12:25:33 models/repo/repo.go:376:LoadUnits() [T[] repo.Units, ID=1, Types: [TypeCode, TypeIssues, TypePullRequests, TypeReleases, TypeWiki, TypeProjects, TypePackages, TypeActions]
2026/03/21 12:25:33 ...s/repo_permission.go:178:func1() [T] Permission Loaded for <User 3:my-user> in <Repository 1:vasudan/my-repo>:
Permissions: {AccessMode:write Units:[0xc00617c040 0xc00617c1c0 0xc00617c340 0xc00617c480 0xc00617c4c0 0xc00617c500 0xc00617c540 0xc00617c680[] UnitsMode:map[TypeCode:write TypeIssues:write TypePullRequests:write TypeReleases:write TypeWiki:write TypeProjects:write TypePackages:write TypeActions:write]}
2026/03/21 12:25:33 ...eb/routing/logger.go:102:func1() [I] router: completed GET /api/v1/repos/vasudan/my-repo? for 10.0.3.177:0, 200 OK in 57.5ms @ repo/repo.go:541(repo.Get)
2026/03/21 12:25:33 ...s/process/manager.go:248:remove() [T] Done 69bec67d: GET: /api/v1/repos/vasudan/my-repo?

As a side note, I did create a PR through the UI and then ran pr view 1. This worked fine.

Steps to Reproduce

text
cargo install forgejo-cli 

fj auth add-key

git clone https://my-forgejo/vasudan/repo.git
git checkout -b "my-branch"
touch test.txt
git add test.txt
git commit -m "test"
git push -u origin my-branch

fj pr create "My PR"

fj Version

text
fj v0.4.0
user agent: forgejo-cli/0.4.0 (https://codeberg.org/forgejo-contrib/forgejo-cli/)
build type: crates.io
    target: aarch64-unknown-linux-gnu

Forgejo Version

version 14.0.3+gitea-1.22.0

Code of Conduct

  • I agree to act in accordance with the CoC & AI Agreement.
  • This issue was not generated by an LLM, even in part.

Expected Behavior When creating a PR using this: fj pr create "My PR" I expect it to create a PR, and if it fails tell me the reason that it failed ### Actual Behavior running this: fj pr create "My PR" yields this: Error: unexpected status code 400 Bad Request Location: /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/forgejo-cli-0.4.0/src/prs.rs:981:40 Since its a 400 its probably something to do with the parameters, but I can't find a way to print out the response body in order to find out what the actual problem is. --- I did enable trace logging on my forgejo instance to try to find out what was happening from the other side, but I don't see anything helpful: 2026/03/21 12:25:33 ...s/process/manager.go:204:Add() [T] Start 69bec67d: GET: /api/v1/repos/vasudan/my-repo? (request) 2026/03/21 12:25:33 ...eb/routing/logger.go:47:func1() [T] router: started GET /api/v1/repos/vasudan/my-repo? for 10.0.3.177:0 2026/03/21 12:25:33 ...vices/auth/oauth2.go:221:Verify() [T[] OAuth2 Authorization: Found token for user[3] 2026/03/21 12:25:33 ...vices/auth/oauth2.go:231:Verify() [T] OAuth2 Authorization: Logged in user \<User 3:my-user\> 2026/03/21 12:25:33 models/repo/repo.go:376:LoadUnits() [T[] repo.Units, ID=1, Types: [TypeCode, TypeIssues, TypePullRequests, TypeReleases, TypeWiki, TypeProjects, TypePackages, TypeActions] 2026/03/21 12:25:33 ...s/repo_permission.go:178:func1() [T] Permission Loaded for \<User 3:my-user\> in \<Repository 1:vasudan/my-repo\>: Permissions: {AccessMode:write Units:[0xc00617c040 0xc00617c1c0 0xc00617c340 0xc00617c480 0xc00617c4c0 0xc00617c500 0xc00617c540 0xc00617c680[] UnitsMode:map[TypeCode:write TypeIssues:write TypePullRequests:write TypeReleases:write TypeWiki:write TypeProjects:write TypePackages:write TypeActions:write]} 2026/03/21 12:25:33 ...eb/routing/logger.go:102:func1() [I] router: completed GET /api/v1/repos/vasudan/my-repo? for 10.0.3.177:0, 200 OK in 57.5ms @ repo/repo.go:541(repo.Get) 2026/03/21 12:25:33 ...s/process/manager.go:248:remove() [T] Done 69bec67d: GET: /api/v1/repos/vasudan/my-repo? --- As a side note, I did create a PR through the UI and then ran pr view 1. This worked fine. ### Steps to Reproduce cargo install forgejo-cli fj auth add-key git clone https://my-forgejo/vasudan/repo.git git checkout -b "my-branch" touch test.txt git add test.txt git commit -m "test" git push -u origin my-branch fj pr create "My PR" ### fj Version text fj v0.4.0 user agent: forgejo-cli/0.4.0 (https://codeberg.org/forgejo-contrib/forgejo-cli/) build type: crates.io target: aarch64-unknown-linux-gnu ### Forgejo Version version 14.0.3+gitea-1.22.0 ### Code of Conduct - [x] I agree to act in accordance with the CoC & AI Agreement. - [x] This issue was not generated by an LLM, even in part.

vasudan added the Kind/Bug label 2026-03-21 17:27:52 +01:00

vasudan changed title from ** "unexpected status code 400 Bad Request" with no response body when creating a PR ** to "unexpected status code 400 Bad Request" when creating a PR 2026-03-21 17:50:47 +01:00

Cyborus commented 2026-03-21 20:20:03 +01:00

Member

Copy link

What permissions are enabled for the token you gave to fj auth add-key?

What permissions are enabled for the token you gave to fj auth add-key?

Cyborus commented 2026-03-21 20:24:00 +01:00

Member

Copy link

Oh, I see in the log it's write for all of them. Hm.

Oh, I see in the log it's write for all of them. Hm.

Cyborus commented 2026-03-21 20:32:01 +01:00

Member

Copy link

Can you grep for 400 Bad Request in your Forgejo instance's logs?

Can you grep for 400 Bad Request in your Forgejo instance's logs?

vasudan commented 2026-03-21 20:51:58 +01:00

Author

Copy link

Hey Cyborus,

These are the token’s permissions

write:misc
write:notification
read:package
write:issue
write:repository
write:user

Hey Cyborus, These are the token’s permissions write:misc write:notification read:package write:issue write:repository write:user

vasudan commented 2026-03-21 20:54:00 +01:00

Author

Copy link

And no I don't see anything in the logs. I did turn on trace logging but what I posted is all I see :\

I did take a look at my traefik logs and the 400 response is coming from this:

text
GET /api/v1/repos/vasudan/my-repo/raw/.forgejo%2Fpull_request_template.md?

Which is odd. I don't have a .forgefo folder in this repo, nor a pull request template.

And no I don't see anything in the logs. I did turn on trace logging but what I posted is all I see :\ I did take a look at my traefik logs and the 400 response is coming from this: GET /api/v1/repos/vasudan/my-repo/raw/.forgejo%2Fpull_request_template.md? Which is odd. I don't have a .forgefo folder in this repo, nor a pull request template.

Cyborus commented 2026-03-21 20:56:54 +01:00

Member

Copy link

That's not unexpected, it always checks to see if there is a template, and the error's line number is within that part. I have no idea why that would fail.

That's not unexpected, it always checks to see if there is a template, and the error's line number is within that part. I have no idea *why* that would fail.

vasudan commented 2026-03-21 21:03:18 +01:00

Author

Copy link

I do see that line 981 of pr.rs deals with getting the template though. I'm not sure why forgejo would return a 400 rather than a 404

https://codeberg.org/forgejo-contrib/forgejo-cli/src/tag/v0.4.0/src/prs.rs#L981

I do see that line 981 of pr.rs deals with getting the template though. I'm not sure why forgejo would return a 400 rather than a 404 https://codeberg.org/forgejo-contrib/forgejo-cli/src/tag/v0.4.0/src/prs.rs#L981

vasudan commented 2026-03-21 21:08:06 +01:00

Author

Copy link

I ran the request with curl, and there is no response body. But the problem is that the url encoding is wrong

This is a 400
GET /api/v1/repos/vasudan/my-repo/raw/.forgejo%2Fpull_request_template.md?

This is a 404
GET /api/v1/repos/vasudan/my-repo/raw/.forgejo/pull_request_template.md?

I ran the request with curl, and there is no response body. But the problem is that the url encoding is wrong This is a 400 GET /api/v1/repos/vasudan/my-repo/raw/.forgejo%2Fpull_request_template.md? This is a 404 GET /api/v1/repos/vasudan/my-repo/raw/.forgejo/pull_request_template.md?

Cyborus commented 2026-03-21 21:32:43 +01:00

Member

Copy link

@vasudan wrote in #381 (comment):

This is a 400
GET /api/v1/repos/vasudan/my-repo/raw/.forgejo%2Fpull_request_template.md?

Thing is, this should work. It works fine on Codeberg. I know @LordMZTE had had issues with nginx rejecting the %2F before, but my Forgejo instance is behind Traefik too and has never had that problem. Still, it may be worth looking into if your reverse proxy is the issue.

@vasudan wrote in https://codeberg.org/forgejo-contrib/forgejo-cli/issues/381#issuecomment-11907474: > This is a 400 > GET /api/v1/repos/vasudan/my-repo/raw/.forgejo%2Fpull_request_template.md? Thing is, this *should* work. It works fine on Codeberg. I know @LordMZTE had had issues with nginx rejecting the %2F before, but my Forgejo instance is behind Traefik too and has never had that problem. Still, it may be worth looking into if your reverse proxy is the issue.

vasudan commented 2026-03-21 21:54:06 +01:00

Author

Copy link

The url path getting encoded still feels wrong. Maybe it’s an ARM thing? If it is an issue then it seems more like an issue with the forgejo-api crate than this repo.

Edit: as an aside, traefik does reject paths that have suspicious characters in them.

The url path getting encoded still feels wrong. Maybe it’s an ARM thing? If it is an issue then it seems more like an issue with the forgejo-api crate than this repo. Edit: as an aside, traefik does reject paths that have suspicious characters in them.

Cyborus commented 2026-03-21 23:37:22 +01:00

Member

Copy link

@vasudan wrote in #381 (comment):

traefik does reject paths that have suspicious characters in them.

That page says %2F is explicitly allowed, though.

@vasudan wrote in https://codeberg.org/forgejo-contrib/forgejo-cli/issues/381#issuecomment-11908581: > traefik does reject paths that have suspicious characters in them. That page says %2F is explicitly *allowed*, though.

Cyborus commented 2026-03-22 00:12:20 +01:00

Member

Copy link

@vasudan wrote in #381 (comment):

The url path getting encoded still feels wrong.

I tested it against a Forgejo instance on my own machine, no reverse proxy at all, and it handled the %2F just fine. Encoding the path is not the issue

@vasudan wrote in https://codeberg.org/forgejo-contrib/forgejo-cli/issues/381#issuecomment-11908581: > The url path getting encoded still feels wrong. I tested it against a Forgejo instance on my own machine, no reverse proxy at all, and it handled the %2F just fine. Encoding the path is not the issue

vasudan commented 2026-03-23 23:42:18 +01:00

Author

Copy link

That page says %2F is explicitly allowed, though.

Oh yea, you're right. I do think the docs are not accurate though due to this comment

I'm getting off subject though.

I tested it against a Forgejo instance on my own machine, no reverse proxy at all, and it handled the %2F just fine. Encoding the path is not the issue

What I meant was that I thinks its bad that the path gets url encoded because it can be blocked by firewalls or apparently traefik and nginx.

I do know that the url encoding has nothing to do with the fj CLI though so I'm gonna close this. Thanks for helping me get to the bottom of this!

> That page says %2F is explicitly _allowed_, though. Oh yea, you're right. I do think the docs are not accurate though due to this comment I'm getting off subject though. > I tested it against a Forgejo instance on my own machine, no reverse proxy at all, and it handled the %2F just fine. Encoding the path is not the issue What I meant was that I thinks its bad that the path gets url encoded because it can be blocked by firewalls or apparently traefik and nginx. I do know that the url encoding has nothing to do with the fj CLI though so I'm gonna close this. Thanks for helping me get to the bottom of this!

👍 1

vasudan closed this issue 2026-03-23 23:42:19 +01:00

LordMZTE commented 2026-03-25 20:44:59 +01:00

Collaborator

Copy link

For context, the reverse proxies aren't really "blocking" it; they're decoding it, turning %2F into /, making the URL invalid. Regarding this issue with nginx, I opened an issue with forgejo docs hoping that we'd find a solution for what a working nginx config would look like: forgejo/docs#1816 Looks like there's a PR there already, so I should probably update my nginx config and test again :P

For context, the reverse proxies aren't really "blocking" it; they're decoding it, turning %2F into /, making the URL invalid. Regarding this issue with nginx, I opened an issue with forgejo docs hoping that we'd find a solution for what a working nginx config would look like: https://codeberg.org/forgejo/docs/issues/1816 Looks like there's a PR there already, so I should probably update my nginx config and test again :P

Sign in to join this conversation.

No Branch/Tag specified

BranchesTags

main

renovate/lock-file-maintenance

renovate/serde-saphyr-0.x

docs/contributing

no-port-in-refspec

login/v16.next.forgejo.org

crates-io-publish

0.5.x

compile-time-fluent

0.4.x

localization-alias-demo

api_url_field

v0.5.0

v0.4.1

v0.4.0

v0.3.0

v0.2.0

v0.1.1

v0.1.0

v0.0.4

v0.0.3

v0.0.2

v0.0.1

Labels

Clear labels[ Kind/Breaking Breaking change that won't be backward compatible

](#)[ Kind/Bug Something is not working

](#)[ Kind/Design Discussion about UI/UX design

](#)[ Kind/Documentation Documentation changes

](#)[ Kind/Enhancement Improve existing functionality

](#)[ Kind/Feature New functionality

](#)[ Kind/Security This is security issue

](#)[ Kind/Testing Issue or pull request related to testing

](#)[ Kind/Upstream This is an issue with upstream software (Forgejo) that is probably not our fault

](#)

[ Priority

Critical The priority is critical

](#)[ Priority

High The priority is high

](#)[ Priority

Low The priority is low

](#)[ Priority

Medium The priority is medium

](#)

[ Reviewed

Confirmed Issue has been confirmed

](#)[ Reviewed

Duplicate This issue or pull request already exists

](#)[ Reviewed

Invalid Invalid issue

](#)[ Reviewed

Won't Fix This issue won't be fixed

](#)

[ Status

Abandoned Somebody has started to work on this but abandoned work

](#)[ Status

Blocked Something is blocking this issue or pull request

](#)[ Status

Need More Info Feedback is required to reproduce issue or to continue work

](#)

[ Suspicious

](#)

No labels Kind/Breaking Kind/Bug Kind/Design Kind/Documentation Kind/Enhancement Kind/Feature Kind/Security Kind/Testing Kind/Upstream [ Priority

Critical ](/forgejo-contrib/forgejo-cli/issues?labels=173012) [ Priority

High ](/forgejo-contrib/forgejo-cli/issues?labels=173013) [ Priority

Low ](/forgejo-contrib/forgejo-cli/issues?labels=173015) [ Priority

Medium ](/forgejo-contrib/forgejo-cli/issues?labels=173014) [ Reviewed

Confirmed ](/forgejo-contrib/forgejo-cli/issues?labels=173007) [ Reviewed

Duplicate ](/forgejo-contrib/forgejo-cli/issues?labels=173005) [ Reviewed

Invalid ](/forgejo-contrib/forgejo-cli/issues?labels=173006) [ Reviewed

Won't Fix ](/forgejo-contrib/forgejo-cli/issues?labels=173008) [ Status

Abandoned ](/forgejo-contrib/forgejo-cli/issues?labels=173011) [ Status

Blocked ](/forgejo-contrib/forgejo-cli/issues?labels=173010) [ Status

Need More Info ](/forgejo-contrib/forgejo-cli/issues?labels=173009) Suspicious

Milestone

Clear milestone

No items

No milestone

Projects

Clear projects

No items

No project

Assignees

Clear assignees

No assignees

3 participants

Notifications Subscribe

Due date

The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference

forgejo-contrib/forgejo-cli#381

WritePreview

Loading…

Add table

| Rows | | | Columns | |

CancelOK

Add a link

Url Description Hint: With a URL in your clipboard, you can paste directly into the editor to create a link.

CancelOK

CancelSave

Reference in a new issue

Repository

forgejo-contrib/forgejo-cli

Title

Body

Create issue

No description provided.

Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?

No Yes