Skip to content

Commit

Permalink
Merge pull request #2603 from fishtown-analytics/fix/windows-is-the-w…
Browse files Browse the repository at this point in the history
…orst-os-ever

remove length check + catch any exceptions on windows
  • Loading branch information
beckjake authored Jun 30, 2020
2 parents a201fc7 + d897164 commit c5c14bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Fixes
- dbt native rendering now avoids turning quoted strings into unquoted strings ([#2597](https://github.com/fishtown-analytics/dbt/issues/2597), [#2599](https://github.com/fishtown-analytics/dbt/pull/2599))
- Hash name of local packages ([#2600](https://github.com/fishtown-analytics/dbt/pull/2600))
- Swallow all file-writing related errors on Windows, regardless of path length or exception type. ([#2603](https://github.com/fishtown-analytics/dbt/pull/2603))


## dbt 0.17.1rc2 (June 25, 2020)
Expand Down
17 changes: 10 additions & 7 deletions core/dbt/clients/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ def write_file(path: str, contents: str = '') -> bool:
make_directory(os.path.dirname(path))
with open(path, 'w', encoding='utf-8') as f:
f.write(str(contents))
except FileNotFoundError as exc:
if (
os.name == 'nt' and
len(path) >= 260
):
except Exception as exc:
# note that you can't just catch FileNotFound, because sometimes
# windows apparently raises something else.
# It's also not sufficient to look at the path length, because
# sometimes windows fails to write paths that are less than the length
# limit. So on windows, suppress all errors that happen from writing
# to disk.
if os.name == 'nt':
# sometimes we get a winerror of 3 which means the path was
# definitely too long, but other times we don't and it means the
# path was just probably too long. This is probably based on the
Expand All @@ -151,8 +154,8 @@ def write_file(path: str, contents: str = '') -> bool:
# all our hard work and the path was still too long. Log and
# continue.
logger.debug(
f'Could not write to path {path}: {reason} '
f'({len(path)} characters)'
f'Could not write to path {path}({len(path)} characters): '
f'{reason}\nexception: {exc}'
)
else:
raise
Expand Down

0 comments on commit c5c14bb

Please sign in to comment.