[Mac]cocoapods出现的错误总结

今天遇到了一个很神奇的cocoapods的错误,在使用pod search xxx的时候,出现一下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

――― MARKDOWN TEMPLATE ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

### Command

``
/usr/local/bin/pod search afnet
``

### Report

* What did you do?

* What did you expect to happen?

* What happened instead?


### Stack

``
CocoaPods : 1.6.1
Ruby : ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
RubyGems : 2.5.2.3
Host : Mac OS X 10.14.3 (18D109)
Xcode : 10.1 (10B61)
Git : git version 2.17.2 (Apple Git-113)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ 05b7b9338bc0e2da13dc75fd3dab0b887257cda0
``

### Plugins

``
cocoapods-deintegrate : 1.0.4
cocoapods-plugins : 1.0.0
cocoapods-search : 1.0.0
cocoapods-stats : 1.1.0
cocoapods-trunk : 1.3.1
cocoapods-try : 1.1.0
``

### Error

``
JSON::ParserError - A JSON text must at least contain two octets!
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/json/common.rb:156:in `initialize'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/json/common.rb:156:in `new'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/json/common.rb:156:in `parse'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-core-1.6.1/lib/cocoapods-core/source/manager.rb:251:in `stored_search_index'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-core-1.6.1/lib/cocoapods-core/source/manager.rb:187:in `updated_search_index'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-core-1.6.1/lib/cocoapods-core/source/manager.rb:118:in `search_by_name'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-search-1.0.0/lib/cocoapods-search/command/search.rb:87:in `local_search'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-search-1.0.0/lib/cocoapods-search/command/search.rb:63:in `run'
/Library/Ruby/Gems/2.3.0/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:22:in `load'
/usr/local/bin/pod:22:in `<main>'
``

――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

[!] Oh no, an error occurred.

Search for existing GitHub issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=A+JSON+text+must+at+least+contain+two+octets%21&type=Issues

If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new

Be sure to first read the contributing guide for details on how to properly submit a ticket:
https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md

Don't forget to anonymize any private data!

Looking for related issues on cocoapods/cocoapods...
- pod search not work JSON ParserError
https://github.com/CocoaPods/CocoaPods/issues/5172 [closed] [10 comments]
30 Aug 2018

- pod install-- JSON::ParserError - A JSON text must at least contain two octets!
https://github.com/CocoaPods/CocoaPods/issues/6692 [closed] [7 comments]
10 Dec 2017

具体我也不知道为毛这样,我试过重装cocoapods不行,试过删除repo再重建也是不行。

搜索了一下JSON::ParserError - A JSON text must at least contain two octets!这句话,说是需要删除~/Library/Caches/CocoaPods/search_index.json文件,接着我去看了这个文件,发现大小是0的,所以删除掉了,再试了一遍pod search xxx,居然就可以了。

甚是神奇,急需开发,暂时就不深究了,先记录下。


回顾了一下,回去在看了search_index.json这个文件,就有21M的大小了,所以我认为的是:这个文件应该就是cocoapods的本地索引文件了,因为新装的cocoapods或者更新了repo仓库,索引文件都需要更新,而应该就是上一次触发索引更新的时候出错中断了,导致没有成功建立索引文件(文件大小为0),所以在执行pod search xxx的时候cocoapods去读取索引文件的时候就出错了。而且我还看了下这个索引文件,这个文件是以json格式保存的,所以之前建立索引文件失败,也就是符合上面那个json解析的错误了。

(•̀ᴗ•́)و ̑̑

Share