Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove length check + catch any exceptions on windows #2603

Merged
merged 2 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Fixes
- Hash name of local packages ([#2600](https:/fishtown-analytics/dbt/pull/2600))
- Swallow all file-writing related errors on Windows, regardless of path length or exception type. ([#2603](https:/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:
drewbanin marked this conversation as resolved.
Show resolved Hide resolved
# 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