Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit c88cb8e

Browse files
fix(cli): ensure entrypoint only exists if npm install passes (#708)
## Change Summary closes #705 I haven't tested these changes yet and have not confirmed that this does achieve the desired behaviour. ## Checklist - [ ] Unit tests for the changes exist - [ ] Tests pass without significant drop in coverage - [ ] Documentation reflects changes where applicable - [ ] Test snapshots have been [updated](https://prisma-client-py.readthedocs.io/en/latest/contributing/contributing/#snapshot-tests) if applicable ## Agreement By submitting this pull request, I confirm that you can use, modify, copy and redistribute this contribution, under the terms of your choice.
1 parent 0ecec2e commit c88cb8e

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/prisma/cli/prisma.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,30 @@ def ensure_cached() -> CLICache:
8888

8989
if not entrypoint.exists():
9090
click.echo('Installing Prisma CLI')
91-
proc = npm.run(
92-
'install',
93-
f'prisma@{config.prisma_version}',
94-
cwd=config.binary_cache_dir,
95-
stdout=subprocess.PIPE,
96-
stderr=subprocess.STDOUT,
97-
)
98-
if proc.returncode != 0:
99-
click.echo(
100-
f'An error ocurred while installing the Prisma CLI; npm install log: {proc.stdout.decode("utf-8")}'
91+
92+
try:
93+
proc = npm.run(
94+
'install',
95+
f'prisma@{config.prisma_version}',
96+
cwd=config.binary_cache_dir,
97+
stdout=subprocess.PIPE,
98+
stderr=subprocess.STDOUT,
10199
)
102-
proc.check_returncode()
100+
if proc.returncode != 0:
101+
click.echo(
102+
f'An error ocurred while installing the Prisma CLI; npm install log: {proc.stdout.decode("utf-8")}'
103+
)
104+
proc.check_returncode()
105+
except Exception:
106+
# as we use the entrypoint existing to check whether or not we should run `npm install`
107+
# we need to make sure it doesn't exist if running `npm install` fails as it will otherwise
108+
# lead to a broken state, https://github.com/RobertCraigie/prisma-client-py/issues/705
109+
if entrypoint.exists():
110+
try:
111+
entrypoint.unlink()
112+
except Exception:
113+
pass
114+
raise
103115

104116
if not entrypoint.exists():
105117
raise PrismaError(

0 commit comments

Comments
 (0)