Skip to content

Commit 6e956a1

Browse files
committed
perf: optimize exception capture
1 parent 42a5269 commit 6e956a1

3 files changed

Lines changed: 58 additions & 68 deletions

File tree

dash_tailwindcss_plugin/cli.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,11 @@ def init_tailwindcss(self, input_css_path: str, config_js_path: str):
124124
Returns:
125125
None
126126
"""
127-
try:
128-
self.tailwind_command.init().install()
129-
logger.info('📝 Next steps:')
130-
logger.info('1. Customize your config file if needed')
131-
logger.info('2. Build CSS with:')
132-
logger.info('dash-tailwindcss-plugin build')
133-
except Exception as e:
134-
logger.error(f'Error initializing Tailwind CSS: {e}')
127+
self.tailwind_command.init().install()
128+
logger.info('📝 Next steps:')
129+
logger.info('1. Customize your config file if needed')
130+
logger.info('2. Build CSS with:')
131+
logger.info('dash-tailwindcss-plugin build')
135132

136133
def build_tailwindcss(self, clean_after: bool):
137134
"""
@@ -143,13 +140,10 @@ def build_tailwindcss(self, clean_after: bool):
143140
Returns:
144141
None
145142
"""
146-
try:
147-
built = self.tailwind_command.init().install().build()
148-
# Clean up if requested
149-
if clean_after:
150-
built.clean()
151-
except Exception as e:
152-
logger.error(f'Error: {e}')
143+
built = self.tailwind_command.init().install().build()
144+
# Clean up if requested
145+
if clean_after:
146+
built.clean()
153147

154148
def watch_tailwindcss(self):
155149
"""
@@ -158,11 +152,7 @@ def watch_tailwindcss(self):
158152
Returns:
159153
None
160154
"""
161-
try:
162-
self.tailwind_command.init().install().watch()
163-
164-
except Exception as e:
165-
logger.error(f'Error watching Tailwind CSS: {e}')
155+
self.tailwind_command.init().install().watch()
166156

167157
def clean_tailwindcss(self):
168158
"""
@@ -171,10 +161,7 @@ def clean_tailwindcss(self):
171161
Returns:
172162
None
173163
"""
174-
try:
175-
self.tailwind_command.clean()
176-
except Exception as e:
177-
logger.error(f'Error cleaning Tailwind CSS: {e}')
164+
self.tailwind_command.clean()
178165

179166

180167
def main():

dash_tailwindcss_plugin/plugin.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,9 @@ def _build_tailwindcss(self):
195195
Returns:
196196
None
197197
"""
198-
try:
199-
built = self.tailwind_command.init().install().build()
200-
if self.clean_after:
201-
built.clean()
202-
except Exception as e:
203-
logger.error(f'❌ Failed to build Tailwind CSS: {e}')
198+
built = self.tailwind_command.init().install().build()
199+
if self.clean_after:
200+
built.clean()
204201

205202

206203
def setup_tailwindcss_plugin(

dash_tailwindcss_plugin/utils.py

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,9 @@ def _check_tailwindcss(self) -> bool:
472472
Returns:
473473
bool: True if Tailwind CSS is installed, False otherwise
474474
"""
475-
cmd = [self.npx_path, f'{self._tailwind_cli} --help']
475+
check_cmd = [self.npx_path, f'{self._tailwind_cli} --help']
476476

477-
result = subprocess.run(cmd, capture_output=True, text=True, env=self.node_env)
477+
result = subprocess.run(check_cmd, capture_output=True, text=True, env=self.node_env)
478478
return result.returncode == 0
479479

480480
def init(self) -> Self:
@@ -518,13 +518,13 @@ def init(self) -> Self:
518518
init_cmd = [self.npm_path, 'init', '-y']
519519
result = subprocess.run(init_cmd, capture_output=True, text=True, env=self.node_env)
520520
if result.returncode != 0:
521-
logger.error(f'❌ Error initializing Tailwind CSS: {result.stderr}')
522-
return self
521+
raise RuntimeError(result.stderr)
523522

524523
logger.info('✅ Tailwind CSS initialized successfully!')
525524

526525
except Exception as e:
527526
logger.error(f'❌ Error initializing Tailwind CSS: {e}')
527+
raise e
528528

529529
return self
530530

@@ -546,13 +546,13 @@ def install(self) -> Self:
546546
]
547547
result = subprocess.run(install_cmd, capture_output=True, text=True, env=self.node_env)
548548
if result.returncode != 0:
549-
logger.error(f'❌ Error installing Tailwind CSS: {result.stderr}')
550-
return self
549+
raise RuntimeError(result.stderr)
551550

552551
logger.info('✅ Tailwind CSS installed successfully!')
553552

554553
except Exception as e:
555554
logger.error(f'❌ Error installing Tailwind CSS: {e}')
555+
raise e
556556

557557
return self
558558

@@ -579,14 +579,14 @@ def build(self) -> Self:
579579
result = subprocess.run(build_cmd, capture_output=True, text=True, env=self.node_env)
580580

581581
if result.returncode != 0:
582-
logger.error(f'❌ Error building Tailwind CSS: {result.stderr}')
583-
return self
582+
raise RuntimeError(result.stderr)
584583

585584
logger.info('✅ Build completed successfully!')
586585
logger.info(f'🎨 Tailwind CSS built successfully to {self.output_css_path}')
587586

588587
except Exception as e:
589588
logger.error(f'❌ Error building Tailwind CSS: {e}')
589+
raise e
590590

591591
return self
592592

@@ -617,6 +617,7 @@ def watch(self) -> Self:
617617

618618
except Exception as e:
619619
logger.error(f'❌ Error watching for changes: {e}')
620+
raise e
620621

621622
return self
622623

@@ -628,35 +629,40 @@ def clean(self) -> Self:
628629
Self: The TailwindCommand instance
629630
"""
630631
logger.info('🧹 Cleaning up generated files...')
631-
files_to_remove = [
632-
self.config_js_path,
633-
'package.json',
634-
'package-lock.json',
635-
self.input_css_path,
636-
]
637-
638-
directories_to_remove = ['node_modules']
639-
640-
# Remove files
641-
for file_path in files_to_remove:
642-
if os.path.exists(file_path):
643-
try:
644-
os.remove(file_path)
645-
if self.is_cli:
646-
logger.info(f'🗑️ Removed {file_path}')
647-
except Exception as e:
648-
logger.warning(f'⚠️ Warning: Could not remove {file_path}: {e}')
649-
650-
# Remove directories
651-
for dir_path in directories_to_remove:
652-
if os.path.exists(dir_path):
653-
try:
654-
shutil.rmtree(dir_path)
655-
if self.is_cli:
656-
logger.info(f'🗑️ Removed {dir_path}')
657-
except Exception as e:
658-
logger.warning(f'⚠️ Warning: Could not remove {dir_path}: {e}')
659-
660-
logger.info('✅ Cleanup completed.')
632+
try:
633+
files_to_remove = [
634+
self.config_js_path,
635+
'package.json',
636+
'package-lock.json',
637+
self.input_css_path,
638+
]
639+
640+
directories_to_remove = ['node_modules']
641+
642+
# Remove files
643+
for file_path in files_to_remove:
644+
if os.path.exists(file_path):
645+
try:
646+
os.remove(file_path)
647+
if self.is_cli:
648+
logger.info(f'🗑️ Removed {file_path}')
649+
except Exception as e:
650+
logger.warning(f'⚠️ Warning: Could not remove {file_path}: {e}')
651+
652+
# Remove directories
653+
for dir_path in directories_to_remove:
654+
if os.path.exists(dir_path):
655+
try:
656+
shutil.rmtree(dir_path)
657+
if self.is_cli:
658+
logger.info(f'🗑️ Removed {dir_path}')
659+
except Exception as e:
660+
logger.warning(f'⚠️ Warning: Could not remove {dir_path}: {e}')
661+
662+
logger.info('✅ Cleanup completed.')
663+
664+
except Exception as e:
665+
logger.error(f'❌ Error cleaning up: {e}')
666+
raise e
661667

662668
return self

0 commit comments

Comments
 (0)