Using Text Editor Breaks Libraries

I’ve had a library that I’ve been building for some time and had a few custom fields for every part. One of these was “Digikey Link” and I thought I’d go through and change them all to “Vendor Link”. Rather than go one by one in the library editor, I opened up the .lib file in a text editor and did a search and replace. Now there is an error when the library is loaded. Is there more to it than the library “just” getting read?

What is the error you get?

file is not a valid component or symbol library file in input/source
[path to file]
line1, offset 0

Can you share the file or at least first lines?

The most likely culprit is that you made some error during editing. Maybe replaced a string too many, or accidentally deleted a comma or a line ending.

KiCad’s files can be edited, as they are text files, but (as far as I know) there are no extensive checks for faults in files.

So I hope you have a backup.
If you have, you can use a source code comparison program, such as for example Meld to compare the two versions, to quicker find the source of the error.

I’ve fiddled with creating a new library and copying and pasting some component definitions. At some point it seems to break again giving the same error as above. The error persists even if I delete all components and leave the library appearing the same in the text editor as a blank library:

EESchema-LIBRARY Version 2.4
#encoding utf-8

#End Library

However if I run diff on the edited library and a brand new blank library:
$ diff New_Library.lib New_Library_0.lib
1c1
< EESchema-LIBRARY Version 2.4

EESchema-LIBRARY Version 2.4

Looking in a hex editor (radare2) at the files shows that the edited one has three bytes added before the “EESc…”, namely 0xEFBB BF[text]

dd if=brokenlibrary.lib of=fixedlibrary.lib bs=1 obs=1 skip=3
seems to have made a library that is fixed.

I wouldn’t think my text editor put those three bytes at the head of the file…

Don’t think, but verify.

We here do not know what you did, or even what editor you used, and even if we did there is not much we can help with such things.

If your investigations lead to a (suspected) bug in KiCad, then a bug report may be in order.

Those 3 bytes are BOM bytes
Use a proper editor that can save files without them.

1 Like

Gotcha. Makes perfect sense. Nice mystery while it lasted.

Thanks guys.

You MUST use UTF-8 plain text, not Rich text. Rich text often contains glyphs and Kicad can’t deal with them (it’s mentioned in official tutorials).

I learned it the hard way - I used ‘Bullets’ to lead some text and it killed my libraries (meaning, they were no longer accessible) it took a good while to figure it…

UTF-8 without BOM usually works fine, though.

On Windows, Notepad++ is my favourite text editor

2 Likes

Yes, UTF-8 is the way to go (not ascii, my old memory is failing me)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.