fix(librarypath): stop cleanEmpty from panicking on a non-trailing empty entry - #272
Merged
viniciussanchez merged 1 commit intoAug 10, 2026
Merged
Conversation
…pty entry range paths caches the slice length once at loop start, but slices.Delete shrinks the backing slice on every match. As soon as one "" sits before the last element, the loop keeps counting against the original length and calls slices.Delete with an index past the now-shorter slice, panicking with "slice bounds out of range". boss install hits this in UpdateLibraryPath, while assembling the global browsing path across every installed dependency's boss.json -- any accumulated "" in that list before the final entry crashes the whole install after every dependency already resolved and was written to disk. Rewritten as the standard in-place filter (write index trailing the read index), which stays correct while mutating the same backing array mid-range. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #272 +/- ##
=======================================
Coverage ? 28.59%
=======================================
Files ? 90
Lines ? 5701
Branches ? 0
=======================================
Hits ? 1630
Misses ? 3932
Partials ? 139
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
O problema
boss installmata o processo com um panic no fim da instalação, depois que todas as dependências já foram resolvidas, baixadas e escritas em disco (boss.json,boss-lock.jsone o.dprojjá atualizados) — só quebra no passo final de "Updating library path":Causa
cleanEmptypercorrepathscomrangee apaga elementos vazios viaslices.Deletedentro do próprio loop:range pathsfixa o tamanho da slice uma vez, no início do loop. Cadaslices.Deleteencolhe a slice de verdade, mas o loop continua contando contra o tamanho original. Basta existir uma string vazia que não seja o último elemento para o índice dorangeultrapassar o tamanho já encolhido — daí oslice bounds out of range.Reproduzi isso na mão, revertendo só essa função para testar
["a", "", "b"]:Mesmo panic, mesma função — confirma que não precisa de múltiplas entradas vazias, uma só (fora da última posição) já derruba.
cleanEmptyé chamado a partir degetNewBrowsingPathsFromDir, dentro deUpdateLibraryPath, que junta os browsing paths declarados noboss.jsonde cada dependência instalada num projeto. Qualquer""que sobre nessa lista acumulada (antes da última posição) derruba oboss installinteiro nesse passo — mesmo com a instalação em si já ter dado certo.A correção
Reescrevi como o filtro in-place idiomático em Go, sem mutar a slice enquanto itera sobre ela:
Índice de escrita nunca ultrapassa o de leitura, então reaproveitar o array de trás (
paths[:0]) é seguro. Removi também o import"slices", que ficou sem uso.Rastreei os call sites (
getNewPathsFromDir,getNewBrowsingPathsFromDir→dproj_util.go/global_util_win.go): em todos, o retorno é reatribuído na mesma variável, então nenhum caller fica com uma slice obsoleta apontando pro array antigo.Testes
TestCleanEmptynovo, cobrindo sem vazios, um vazio no meio, vários vazios e todos vazios — os dois últimos casos derrubavam a versão antiga.go test ./utils/librarypath/...verde, sem regressão nos testes já existentes do pacote.go build ./...ego vet ./...limpos.🤖 Generated with Claude Code